Skip to content

Commit ff6e173

Browse files
committed
workers.erb => workers.mustache
1 parent 424a3ce commit ff6e173

File tree

6 files changed

+183
-121
lines changed

6 files changed

+183
-121
lines changed

lib/resque/server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
require 'resque/server/helpers'
1010
require 'resque/server/views/layout'
11+
require 'resque/server/views/worker_list'
1112

1213
module Resque
1314
class Server < Sinatra::Base
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{{#worker?}}
2+
<h1>Worker {{to_s}}</h1>
3+
<table class='workers'>
4+
<tr>
5+
<th>&nbsp;</th>
6+
<th>Host</th>
7+
<th>Pid</th>
8+
<th>Started</th>
9+
<th>Queues</th>
10+
<th>Processed</th>
11+
<th>Failed</th>
12+
<th>Processing</th>
13+
</tr>
14+
<tr>
15+
<td class='icon'>
16+
{{{state_icon}}}
17+
18+
<% host, pid, queues = worker.to_s.split(':') %>
19+
<td>{{worker_host}}</td>
20+
<td>{{worker_pid}}</td>
21+
<td><span class="time">{{started}}</span></td>
22+
<td class='queues'>
23+
{{linked_queues}}
24+
</td>
25+
<td>{{processed}}</td>
26+
<td>{{failed}}></td>
27+
<td class='process'>
28+
{{#processing}}
29+
{{#data}}
30+
<code>{{#payload}}{{class}}{{/payload}}</code>
31+
<small>
32+
<a class="queue time" href="{{working_url}}">{{run_at}}</a>
33+
</small>
34+
{{/data}}
35+
{{/processing}}
36+
37+
{{#not_processing}}
38+
<span class='waiting'>Waiting for a job...</span>
39+
{{/not_processing}}
40+
</td>
41+
</tr>
42+
</table>
43+
{{/worker?}}
44+
45+
{{#worker_not_found?}}
46+
<h1>Worker doesn't exist</h1>
47+
{{/worker_not_found?}}
48+
49+
{{#all_workers?}}
50+
<h1 class='wi'>{{size}} Workers</h1>
51+
<p class='intro'>
52+
The workers listed below are all registered as active on your system.
53+
</p>
54+
55+
<table class='workers'>
56+
<tr>
57+
<th>&nbsp;</th>
58+
<th>Where</th>
59+
<th>Queues</th>
60+
<th>Processing</th>
61+
</tr>
62+
{{#workers}}
63+
<tr class="{{state}}">
64+
<td class='icon'>
65+
{{{state_icon}}}
66+
</td>
67+
68+
<td class='where'>
69+
<a href="{{worker_url}}">{{worker_host}}:{{worker_pid}}</a></td>
70+
<td class='queues'>
71+
{{{linked_queues}}}
72+
</td>
73+
74+
<td class='process'>
75+
{{#processing}}
76+
{{#queue}}
77+
<code>{{#payload}}{{class}}{{/payload}}</code>
78+
<small>
79+
<a class="queue time" href="{{working_url}}">{{run_at}}</a>
80+
</small>
81+
{{/queue}}
82+
{{/processing}}
83+
84+
{{#not_processing}}
85+
<span class='waiting'>Waiting for a job...</span>
86+
{{/not_processing}}
87+
</td>
88+
</tr>
89+
{{/workers}}
90+
91+
{{#no_workers?}}
92+
<tr>
93+
<td colspan='4' class='no-data'>There are no registered workers</td>
94+
</tr>
95+
{{/no_workers?}}
96+
</table>
97+
98+
<%=poll%>
99+
{{/all_workers?}}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module Resque
2+
module Views
3+
class WorkerList < Layout
4+
def state_icon
5+
state = self[:state]
6+
%(<img src="#{u(state)}.png" alt="#{state}" title="#{state}">)
7+
end
8+
9+
# If we're not looking at a single worker, we're looking at all
10+
# fo them.
11+
def all_workers?
12+
!params[:id]
13+
end
14+
15+
# Host where the current worker lives.
16+
def worker_host
17+
worker_parts[0]
18+
end
19+
20+
# PID of the current worker.
21+
def worker_pid
22+
worker_parts[1]
23+
end
24+
25+
# Queues the current worker is concerned with.
26+
def worker_queues
27+
worker_parts[2..-1]
28+
end
29+
30+
# The current worker's name split into three parts:
31+
# [ host, pid, queues ]
32+
def worker_parts
33+
self[:to_s].split(':')
34+
end
35+
36+
# Worker URL of the current worker
37+
def worker_url
38+
u "/workers/#{self[:to_s]}"
39+
end
40+
41+
# Working URL of the current working
42+
def working_url
43+
u "/working/#{self[:to_s]}"
44+
end
45+
end
46+
end
47+
end

lib/resque/server/views/workers.erb

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/resque/server/views/workers.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Resque
2+
module Views
3+
class Workers < WorkerList
4+
def worker?
5+
if id = params[:id]
6+
Resque::Worker.find(id)
7+
end
8+
end
9+
10+
def worker_not_found?
11+
params[:id] && !Resque::Worker.find(id)
12+
end
13+
14+
def workers
15+
Resque.workers.sort_by { |w| w.to_s }
16+
end
17+
18+
def linked_queues
19+
links = self[:queues].map do |q|
20+
%(<a class="queue-tag" href="#{u("/queues/#{q}")}">#{q}</a>)
21+
end
22+
23+
links.join('')
24+
end
25+
26+
def no_workers?
27+
workers.empty?
28+
end
29+
30+
def not_processing
31+
!self[:processing]
32+
end
33+
end
34+
end
35+
end

lib/resque/server/views/working.rb

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Resque
22
module Views
3-
class Working < Layout
3+
class Working < WorkerList
44
# If we're only looking at a single worker, return it as the
55
# context.
66
def single_worker?
@@ -10,12 +10,6 @@ def single_worker?
1010
end
1111
end
1212

13-
# If we're not looking at a single worker, we're looking at all
14-
# fo them.
15-
def all_workers?
16-
!params[:id]
17-
end
18-
1913
# A sorted array of workers currently working.
2014
def working
2115
Resque.working.
@@ -43,32 +37,6 @@ def workers_total
4337
Resque.workers.size
4438
end
4539

46-
# A full URL to the icon representing a worker's state.
47-
def state_icon
48-
u(self[:state]) + '.png'
49-
end
50-
51-
# Host where the current worker lives.
52-
def worker_host
53-
worker_parts[0]
54-
end
55-
56-
# PID of the current worker.
57-
def worker_pid
58-
worker_parts[1]
59-
end
60-
61-
# Queues the current worker is concerned with.
62-
def worker_queues
63-
worker_parts[2..-1]
64-
end
65-
66-
# The current worker's name split into three parts:
67-
# [ host, pid, queues ]
68-
def worker_parts
69-
self[:to_s].split(':')
70-
end
71-
7240
# TODO: Mustache method_missing this guy
7341
def queue
7442
self[:queue]
@@ -78,16 +46,6 @@ def queue
7846
def queue_url
7947
u "/queues/#{queue}"
8048
end
81-
82-
# Worker URL of the current worker
83-
def worker_url
84-
u "/workers/#{self[:to_s]}"
85-
end
86-
87-
# Working URL of the current working
88-
def working_url
89-
u "/working/#{self[:to_s]}"
90-
end
9149
end
9250
end
9351
end

0 commit comments

Comments
 (0)