Skip to content

Commit a1b5452

Browse files
committed
Merge pull request resque#247 from backupify/fix_resque_web_race_condition
Fix resque web race condition
2 parents 084e4df + 4d0abb0 commit a1b5452

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/resque/server/views/working.erb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727

2828
<% else %>
2929

30-
<% workers = resque.working.reject { |w| w.idle? } %>
31-
<h1 class='wi'><%= workers.size %> of <%= resque.workers.size %> Workers Working</h1>
30+
<%
31+
workers = resque.working
32+
jobs = workers.collect {|w| w.job }
33+
worker_jobs = workers.zip(jobs)
34+
worker_jobs = worker_jobs.reject { |w, j| w.idle? }
35+
%>
36+
37+
<h1 class='wi'><%= worker_jobs.size %> of <%= resque.workers.size %> Workers Working</h1>
3238
<p class='intro'>The list below contains all workers which are currently running a job.</p>
3339
<table class='workers'>
3440
<tr>
@@ -37,15 +43,13 @@
3743
<th>Queue</th>
3844
<th>Processing</th>
3945
</tr>
40-
<% if workers.empty? %>
46+
<% if worker_jobs.empty? %>
4147
<tr>
4248
<td colspan="4" class='no-data'>Nothing is happening right now...</td>
4349
</tr>
4450
<% end %>
4551

46-
<% for worker in workers.sort_by { |w| w.job['run_at'] ? w.job['run_at'] : '' } %>
47-
<% job = worker.job %>
48-
52+
<% worker_jobs.sort_by {|w, j| j['run_at'] ? j['run_at'] : '' }.each do |worker, job| %>
4953
<tr>
5054
<td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
5155
<% host, pid, queues = worker.to_s.split(':') %>

0 commit comments

Comments
 (0)