Skip to content

Commit 424a3ce

Browse files
committed
Some comments, use the worker object as a context
1 parent fe640c2 commit 424a3ce

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

lib/resque/server/templates/working.mustache

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,23 @@
5757
</td>
5858

5959
<td class='queues queue'>
60-
{{#worker}}
61-
{{#job}}
62-
<a class="queue-tag" href="{{queue_url}}">
63-
{{queue}}
64-
{{/job}}
65-
{{/worker}}
60+
{{#job}}
61+
<a class="queue-tag" href="{{queue_url}}">
62+
{{queue}}
63+
{{/job}}
6664
</a>
6765
</td>
6866

6967
<td class='process'>
70-
{{#worker}}
71-
{{#job}}
72-
<code>{{#payload}}{{class}}{{/payload}}</code>
73-
<small>
74-
<a class="queue time" href="{{working_url}}">{{run_at}}</a>
75-
</small>
76-
{{/job}}
77-
{{#no_job}}
78-
<span class='waiting'>Waiting for a job...</span>
79-
{{/no_job}}
80-
{{/worker}}
68+
{{#job}}
69+
<code>{{#payload}}{{class}}{{/payload}}</code>
70+
<small>
71+
<a class="queue time" href="{{working_url}}">{{run_at}}</a>
72+
</small>
73+
{{/job}}
74+
{{#no_job}}
75+
<span class='waiting'>Waiting for a job...</span>
76+
{{/no_job}}
8177
</td>
8278
</tr>
8379
{{/working}}

lib/resque/server/views/working.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,93 @@
11
module Resque
22
module Views
33
class Working < Layout
4+
# If we're only looking at a single worker, return it as the
5+
# context.
46
def single_worker?
57
id = params[:id]
68
if id && (worker = Resque::Worker.find(id)) && worker.job
79
worker
810
end
911
end
1012

13+
# If we're not looking at a single worker, we're looking at all
14+
# fo them.
1115
def all_workers?
1216
!params[:id]
1317
end
1418

19+
# A sorted array of workers currently working.
1520
def working
1621
Resque.working.
1722
sort_by { |w| w.job['run_at'] ? w.job['run_at'] : '' }.
18-
reject { |w| w.idle? }.
19-
map { |worker| { :worker => worker } }
23+
reject { |w| w.idle? }
2024
end
2125

26+
# Is no one working?
2227
def none_working?
2328
working.empty?
2429
end
2530

31+
# Does this context have a job?
2632
def no_job
2733
!self[:job]
2834
end
2935

36+
# The number of workers currently working.
3037
def workers_working
3138
Resque.working.size
3239
end
3340

41+
# The number of workers total.
3442
def workers_total
3543
Resque.workers.size
3644
end
3745

46+
# A full URL to the icon representing a worker's state.
3847
def state_icon
39-
u(self[:worker].state) + '.png'
48+
u(self[:state]) + '.png'
4049
end
4150

51+
# Host where the current worker lives.
4252
def worker_host
4353
worker_parts[0]
4454
end
4555

56+
# PID of the current worker.
4657
def worker_pid
4758
worker_parts[1]
4859
end
4960

61+
# Queues the current worker is concerned with.
5062
def worker_queues
5163
worker_parts[2..-1]
5264
end
5365

66+
# The current worker's name split into three parts:
67+
# [ host, pid, queues ]
5468
def worker_parts
55-
self[:worker].to_s.split(':')
69+
self[:to_s].split(':')
5670
end
5771

72+
# TODO: Mustache method_missing this guy
5873
def queue
5974
self[:queue]
6075
end
6176

77+
# URL of the current job's queue
6278
def queue_url
6379
u "/queues/#{queue}"
6480
end
6581

82+
# Worker URL of the current worker
6683
def worker_url
67-
u "/workers/#{self[:worker]}"
84+
u "/workers/#{self[:to_s]}"
6885
end
6986

87+
# Working URL of the current working
7088
def working_url
71-
u "/working/#{self[:worker]}"
89+
u "/working/#{self[:to_s]}"
7290
end
7391
end
7492
end
7593
end
76-

0 commit comments

Comments
 (0)