|
1 | 1 | module Resque
|
2 | 2 | module Views
|
3 | 3 | class Working < Layout
|
| 4 | + # If we're only looking at a single worker, return it as the |
| 5 | + # context. |
4 | 6 | def single_worker?
|
5 | 7 | id = params[:id]
|
6 | 8 | if id && (worker = Resque::Worker.find(id)) && worker.job
|
7 | 9 | worker
|
8 | 10 | end
|
9 | 11 | end
|
10 | 12 |
|
| 13 | + # If we're not looking at a single worker, we're looking at all |
| 14 | + # fo them. |
11 | 15 | def all_workers?
|
12 | 16 | !params[:id]
|
13 | 17 | end
|
14 | 18 |
|
| 19 | + # A sorted array of workers currently working. |
15 | 20 | def working
|
16 | 21 | Resque.working.
|
17 | 22 | 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? } |
20 | 24 | end
|
21 | 25 |
|
| 26 | + # Is no one working? |
22 | 27 | def none_working?
|
23 | 28 | working.empty?
|
24 | 29 | end
|
25 | 30 |
|
| 31 | + # Does this context have a job? |
26 | 32 | def no_job
|
27 | 33 | !self[:job]
|
28 | 34 | end
|
29 | 35 |
|
| 36 | + # The number of workers currently working. |
30 | 37 | def workers_working
|
31 | 38 | Resque.working.size
|
32 | 39 | end
|
33 | 40 |
|
| 41 | + # The number of workers total. |
34 | 42 | def workers_total
|
35 | 43 | Resque.workers.size
|
36 | 44 | end
|
37 | 45 |
|
| 46 | + # A full URL to the icon representing a worker's state. |
38 | 47 | def state_icon
|
39 |
| - u(self[:worker].state) + '.png' |
| 48 | + u(self[:state]) + '.png' |
40 | 49 | end
|
41 | 50 |
|
| 51 | + # Host where the current worker lives. |
42 | 52 | def worker_host
|
43 | 53 | worker_parts[0]
|
44 | 54 | end
|
45 | 55 |
|
| 56 | + # PID of the current worker. |
46 | 57 | def worker_pid
|
47 | 58 | worker_parts[1]
|
48 | 59 | end
|
49 | 60 |
|
| 61 | + # Queues the current worker is concerned with. |
50 | 62 | def worker_queues
|
51 | 63 | worker_parts[2..-1]
|
52 | 64 | end
|
53 | 65 |
|
| 66 | + # The current worker's name split into three parts: |
| 67 | + # [ host, pid, queues ] |
54 | 68 | def worker_parts
|
55 |
| - self[:worker].to_s.split(':') |
| 69 | + self[:to_s].split(':') |
56 | 70 | end
|
57 | 71 |
|
| 72 | + # TODO: Mustache method_missing this guy |
58 | 73 | def queue
|
59 | 74 | self[:queue]
|
60 | 75 | end
|
61 | 76 |
|
| 77 | + # URL of the current job's queue |
62 | 78 | def queue_url
|
63 | 79 | u "/queues/#{queue}"
|
64 | 80 | end
|
65 | 81 |
|
| 82 | + # Worker URL of the current worker |
66 | 83 | def worker_url
|
67 |
| - u "/workers/#{self[:worker]}" |
| 84 | + u "/workers/#{self[:to_s]}" |
68 | 85 | end
|
69 | 86 |
|
| 87 | + # Working URL of the current working |
70 | 88 | def working_url
|
71 |
| - u "/working/#{self[:worker]}" |
| 89 | + u "/working/#{self[:to_s]}" |
72 | 90 | end
|
73 | 91 | end
|
74 | 92 | end
|
75 | 93 | end
|
76 |
| - |
|
0 commit comments