File tree Expand file tree Collapse file tree 6 files changed +183
-121
lines changed Expand file tree Collapse file tree 6 files changed +183
-121
lines changed Original file line number Diff line number Diff line change 8
8
9
9
require 'resque/server/helpers'
10
10
require 'resque/server/views/layout'
11
+ require 'resque/server/views/worker_list'
11
12
12
13
module Resque
13
14
class Server < Sinatra ::Base
Original file line number Diff line number Diff line change
1
+ { {#worker?} }
2
+ <h1 >Worker { {to_s} }</h1 >
3
+ <table class =' workers' >
4
+ <tr >
5
+ <th >  ; </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 >  ; </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?} }
Original file line number Diff line number Diff line change
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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
1
module Resque
2
2
module Views
3
- class Working < Layout
3
+ class Working < WorkerList
4
4
# If we're only looking at a single worker, return it as the
5
5
# context.
6
6
def single_worker?
@@ -10,12 +10,6 @@ def single_worker?
10
10
end
11
11
end
12
12
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
-
19
13
# A sorted array of workers currently working.
20
14
def working
21
15
Resque . working .
@@ -43,32 +37,6 @@ def workers_total
43
37
Resque . workers . size
44
38
end
45
39
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
-
72
40
# TODO: Mustache method_missing this guy
73
41
def queue
74
42
self [ :queue ]
@@ -78,16 +46,6 @@ def queue
78
46
def queue_url
79
47
u "/queues/#{ queue } "
80
48
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
91
49
end
92
50
end
93
51
end
You can’t perform that action at this time.
0 commit comments