Skip to content

Commit 76f0597

Browse files
committed
Web UI: Group /workers page by hostnames
1 parent 3c7bd9e commit 76f0597

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

lib/resque/server.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ def show_args(args)
8080
Array(args).map { |a| a.inspect }.join("\n")
8181
end
8282

83+
def worker_hosts
84+
@worker_hosts ||= worker_hosts!
85+
end
86+
87+
def worker_hosts!
88+
hosts = Hash.new { [] }
89+
90+
Resque.workers.each do |worker|
91+
host, _ = worker.to_s.split(':')
92+
hosts[host] += [worker.to_s]
93+
end
94+
95+
hosts
96+
end
97+
8398
def partial?
8499
@partial
85100
end

lib/resque/server/views/workers.erb

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<% @subtabs = worker_hosts.keys.sort unless worker_hosts.size == 1 %>
2+
13
<% if params[:id] && worker = Resque::Worker.find(params[:id]) %>
24

35
<h1>Worker <%= worker %></h1>
@@ -34,13 +36,19 @@
3436
</tr>
3537
</table>
3638

37-
<% elsif params[:id] %>
39+
<% elsif params[:id] && !worker_hosts.keys.include?(params[:id]) && params[:id] != 'all' %>
3840

3941
<h1>Worker doesn't exist</h1>
4042

41-
<% else %>
43+
<% elsif worker_hosts.size == 1 || params[:id] %>
4244

43-
<h1 class='wi'><%= resque.workers.size %> Workers</h1>
45+
<% if worker_hosts.size == 1 || params[:id] == 'all' %>
46+
<% workers = Resque.workers %>
47+
<% else %>
48+
<% workers = worker_hosts[params[:id]].map { |id| Resque::Worker.find(id) } %>
49+
<% end %>
50+
51+
<h1 class='wi'><%= workers.size %> Workers</h1>
4452
<p class='intro'>The workers listed below are all registered as active on your system.</p>
4553
<table class='workers'>
4654
<tr>
@@ -49,7 +57,7 @@
4957
<th>Queues</th>
5058
<th>Processing</th>
5159
</tr>
52-
<% for worker in (workers = resque.workers.sort_by { |w| w.to_s }) %>
60+
<% for worker in (workers = workers.sort_by { |w| w.to_s }) %>
5361
<tr class="<%=state = worker.state%>">
5462
<td class='icon'><img src="<%=u state %>.png" alt="<%= state %>" title="<%= state %>"></td>
5563

@@ -75,4 +83,27 @@
7583
<% end %>
7684
</table>
7785
<%=poll%>
86+
87+
<% else %>
88+
89+
<h1 class='wi'>Workers</h1>
90+
<p class='intro'>The hostnames below all have registered workers. Select a hostname to view its workers, or "all" to see all workers.</p>
91+
<table class='queues'>
92+
<tr>
93+
<th>Hostname</th>
94+
<th>Workers</th>
95+
</tr>
96+
<% for hostname, workers in worker_hosts %>
97+
<tr>
98+
<td class='queue'><a class="queue" href="<%= url "workers/#{hostname}" %>"><%= hostname %></a></td>
99+
<td class='size'><%= workers.size %></td>
100+
</tr>
101+
<% end %>
102+
<tr class="failed">
103+
<td class='queue failed'><a class="queue" href="<%= url "workers/all" %>">all workers</a></td>
104+
<td class='size'><%= Resque.workers.size %></td>
105+
</tr>
106+
</table>
107+
108+
78109
<% end %>

0 commit comments

Comments
 (0)