resque_ui 3.1.7 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/README.markdown +93 -4
- data/VERSION.yml +2 -2
- data/app/controllers/resque_controller.rb +12 -0
- data/app/views/resque/_workers.html.erb +115 -95
- data/lib/resque_ui/cap_recipes.rb +21 -1
- data/lib/resque_ui/overrides/resque/job.rb +66 -2
- data/lib/resque_ui/overrides/resque/worker.rb +72 -10
- data/lib/resque_ui/overrides/resque_status/job_with_status.rb +45 -1
- data/lib/resque_ui/overrides/resque_status/status.rb +5 -0
- data/rdoc/Resque/Job.html +68 -4
- data/rdoc/Resque/JobWithStatus.html +161 -7
- data/rdoc/Resque/Status.html +47 -5
- data/rdoc/Resque/Worker.html +313 -64
- data/rdoc/created.rid +8 -8
- data/rdoc/index.html +27 -7
- data/rdoc/lib/resque_ui/cap_rb.html +1 -1
- data/rdoc/lib/resque_ui/cap_recipes_rb.html +2 -2
- data/rdoc/lib/resque_ui/overrides/resque/job_rb.html +2 -2
- data/rdoc/lib/resque_ui/overrides/resque/resque_rb.html +1 -1
- data/rdoc/lib/resque_ui/overrides/resque/worker_rb.html +2 -2
- data/rdoc/lib/resque_ui/overrides/resque_scheduler/resque_scheduler_rb.html +1 -1
- data/rdoc/lib/resque_ui/overrides/resque_status/chained_job_with_status_rb.html +1 -1
- data/rdoc/lib/resque_ui/overrides/resque_status/job_with_status_rb.html +2 -2
- data/rdoc/lib/resque_ui/overrides/resque_status/status_rb.html +2 -2
- data/rdoc/lib/resque_ui_rb.html +2 -2
- data/resque_ui.gemspec +2 -2
- metadata +2 -2
@@ -22,8 +22,10 @@ module Resque
|
|
22
22
|
|
23
23
|
alias_method :id, :to_s
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# When the worker gets the -USR2 signal, to_s may give a different value for the thread and queue portion
|
26
|
+
def pause_key
|
27
|
+
key = to_s.split(':')
|
28
|
+
"worker:#{key.first}:#{key.second}:all_workers:paused"
|
27
29
|
end
|
28
30
|
|
29
31
|
def thread
|
@@ -76,6 +78,35 @@ module Resque
|
|
76
78
|
@shutdown = true
|
77
79
|
end
|
78
80
|
|
81
|
+
def paused
|
82
|
+
redis.get pause_key
|
83
|
+
end
|
84
|
+
|
85
|
+
# are we paused?
|
86
|
+
# OVERRIDE so UI can tell if we're paused
|
87
|
+
def paused?
|
88
|
+
@paused || paused.present?
|
89
|
+
end
|
90
|
+
|
91
|
+
# Stop processing jobs after the current one has completed (if we're
|
92
|
+
# currently running one).
|
93
|
+
#OVERRIDE to set a redis key so UI knows it's paused too
|
94
|
+
# Would prefer to call super but get no superclass method error
|
95
|
+
def pause_processing
|
96
|
+
log "USR2 received; pausing job processing"
|
97
|
+
@paused = true
|
98
|
+
redis.set(pause_key, Time.now.to_s)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Start processing jobs again after a pause
|
102
|
+
#OVERRIDE to set remove redis key so UI knows it's unpaused too
|
103
|
+
# Would prefer to call super but get no superclass method error
|
104
|
+
def unpause_processing
|
105
|
+
log "CONT received; resuming job processing"
|
106
|
+
@paused = false
|
107
|
+
redis.del(pause_key)
|
108
|
+
end
|
109
|
+
|
79
110
|
# Looks for any workers which should be running on this server
|
80
111
|
# and, if they're not, removes them from Redis.
|
81
112
|
#
|
@@ -96,6 +127,29 @@ module Resque
|
|
96
127
|
end
|
97
128
|
end
|
98
129
|
|
130
|
+
# Unregisters ourself as a worker. Useful when shutting down.
|
131
|
+
# OVERRIDE to also remove the pause key
|
132
|
+
# Would prefer to call super but get no superclass method error
|
133
|
+
def unregister_worker
|
134
|
+
# If we're still processing a job, make sure it gets logged as a
|
135
|
+
# failure.
|
136
|
+
if (hash = processing) && !hash.empty?
|
137
|
+
job = Job.new(hash['queue'], hash['payload'])
|
138
|
+
# Ensure the proper worker is attached to this job, even if
|
139
|
+
# it's not the precise instance that died.
|
140
|
+
job.worker = self
|
141
|
+
job.fail(DirtyExit.new)
|
142
|
+
end
|
143
|
+
|
144
|
+
redis.srem(:workers, self)
|
145
|
+
redis.del("worker:#{self}")
|
146
|
+
redis.del("worker:#{self}:started")
|
147
|
+
redis.del(pause_key)
|
148
|
+
|
149
|
+
Stat.clear("processed:#{self}")
|
150
|
+
Stat.clear("failed:#{self}")
|
151
|
+
end
|
152
|
+
|
99
153
|
def all_workers_in_pid_working
|
100
154
|
workers_in_pid.select { |w| (hash = w.processing) && !hash.empty? }
|
101
155
|
end
|
@@ -168,14 +222,6 @@ module Resque
|
|
168
222
|
end.compact
|
169
223
|
end
|
170
224
|
|
171
|
-
# Returns an array of string pids of all the other workers on this
|
172
|
-
# machine. Useful when pruning dead workers on startup.
|
173
|
-
def worker_pids
|
174
|
-
`ps -A -o pid,command | grep [r]esque`.split("\n").map do |line|
|
175
|
-
line.split(' ')[0]
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
225
|
def status=(status)
|
180
226
|
data = encode(job.merge('status' => status))
|
181
227
|
redis.set("worker:#{self}", data)
|
@@ -208,6 +254,22 @@ module Resque
|
|
208
254
|
end
|
209
255
|
end
|
210
256
|
|
257
|
+
def pause
|
258
|
+
if Rails.env =~ /development|test/
|
259
|
+
system("kill -USR2 #{self.pid}")
|
260
|
+
else
|
261
|
+
system("cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:pause_worker pid=#{self.pid} host=#{self.ip}")
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def continue
|
266
|
+
if Rails.env =~ /development|test/
|
267
|
+
system("kill -CONT #{self.pid}")
|
268
|
+
else
|
269
|
+
system("cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:continue_worker pid=#{self.pid} host=#{self.ip}")
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
211
273
|
def restart
|
212
274
|
queues = self.queues_in_pid.join('#')
|
213
275
|
quit
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Resque
|
2
2
|
class JobWithStatus
|
3
|
+
|
4
|
+
attr_reader :worker
|
5
|
+
|
3
6
|
# Adds a job of type <tt>klass<tt> to the queue with <tt>options<tt>.
|
4
7
|
# Returns the UUID of the job
|
5
8
|
# override to pass actual parameters instead of a single hash, to make backward compatible with existing resque jobs.
|
@@ -16,6 +19,47 @@ module Resque
|
|
16
19
|
def tick(*messages)
|
17
20
|
kill! if should_kill? || status.killed?
|
18
21
|
set_status({'status' => 'working'}, *messages)
|
22
|
+
# check to see if the worker doing the job has been paused, pause the job if so
|
23
|
+
if self.worker && self.worker.paused?
|
24
|
+
loop do
|
25
|
+
# Set the status to paused.
|
26
|
+
# May need to do this repeatedly because there could be workers in a chained job still doing work.
|
27
|
+
pause! unless status.paused?
|
28
|
+
break unless self.worker.paused?
|
29
|
+
sleep 60
|
30
|
+
end
|
31
|
+
set_status({'status' => 'working'}, *messages) unless status && (status.completed? || status.paused? || status.killed?)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Pause the current job, setting the status to 'paused'
|
36
|
+
def pause!
|
37
|
+
set_status({
|
38
|
+
'status' => 'paused',
|
39
|
+
'message' => "#{worker} paused at #{Time.now}"
|
40
|
+
})
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create a new instance with <tt>uuid</tt> and <tt>options</tt>
|
44
|
+
# OVERRIDE to add the worker attr
|
45
|
+
def initialize(uuid, worker, options = {})
|
46
|
+
@uuid = uuid
|
47
|
+
@options = options
|
48
|
+
@worker = worker
|
49
|
+
end
|
50
|
+
|
51
|
+
# This is the method called by Resque::Worker when processing jobs. It
|
52
|
+
# creates a new instance of the job class and populates it with the uuid and
|
53
|
+
# options.
|
54
|
+
#
|
55
|
+
# You should not override this method, rather the <tt>perform</tt> instance method.
|
56
|
+
# OVERRIDE to pass the block in order to set the worker status, returns the worker object
|
57
|
+
def self.perform(uuid=nil, options = {})
|
58
|
+
uuid ||= Resque::Status.generate_uuid
|
59
|
+
worker = yield
|
60
|
+
instance = new(uuid, worker, options)
|
61
|
+
instance.safe_perform! { |status| yield status if block_given? }
|
62
|
+
instance
|
19
63
|
end
|
20
64
|
|
21
65
|
# Run by the Resque::Worker when processing this job. It wraps the <tt>perform</tt>
|
@@ -25,7 +69,7 @@ module Resque
|
|
25
69
|
def safe_perform!
|
26
70
|
unless should_kill? || (status && status.killed?)
|
27
71
|
set_status({'status' => 'working'})
|
28
|
-
perform
|
72
|
+
perform { |status| yield status if block_given? }
|
29
73
|
kill! if should_kill?
|
30
74
|
completed unless status && status.completed?
|
31
75
|
on_success if respond_to?(:on_success)
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Resque
|
2
2
|
class Status
|
3
|
+
# The STATUSES constant is frozen, so we'll just manually add the paused? method here
|
4
|
+
def paused?
|
5
|
+
self['status'] === 'paused'
|
6
|
+
end
|
7
|
+
|
3
8
|
# Return the <tt>num</tt> most recent status/job UUIDs in reverse chronological order.
|
4
9
|
#override the gem to fix the ordering
|
5
10
|
def self.status_ids(range_start = nil, range_end = nil)
|
data/rdoc/Resque/Job.html
CHANGED
@@ -163,16 +163,80 @@
|
|
163
163
|
|
164
164
|
<p>Attempts to perform the work represented by this job instance. Calls <a
|
165
165
|
href="Job.html#method-i-perform">perform</a> on the class given in the
|
166
|
-
payload with the arguments given in the payload.
|
167
|
-
|
166
|
+
payload with the arguments given in the payload. A block is sent so a
|
167
|
+
message can be yielded back to be set in the worker.</p>
|
168
168
|
|
169
169
|
|
170
170
|
|
171
171
|
<div class="method-source-code" id="perform-source">
|
172
172
|
<pre>
|
173
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/job.rb, line
|
173
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/job.rb, line 8</span>
|
174
174
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">perform</span>
|
175
|
-
<span class="ruby-identifier">
|
175
|
+
<span class="ruby-identifier">job</span> = <span class="ruby-identifier">payload_class</span>
|
176
|
+
<span class="ruby-identifier">job_args</span> = <span class="ruby-identifier">args</span> <span class="ruby-operator">||</span> []
|
177
|
+
<span class="ruby-identifier">job_was_performed</span> = <span class="ruby-keyword">false</span>
|
178
|
+
|
179
|
+
<span class="ruby-identifier">before_hooks</span> = <span class="ruby-constant">Plugin</span>.<span class="ruby-identifier">before_hooks</span>(<span class="ruby-identifier">job</span>)
|
180
|
+
<span class="ruby-identifier">around_hooks</span> = <span class="ruby-constant">Plugin</span>.<span class="ruby-identifier">around_hooks</span>(<span class="ruby-identifier">job</span>)
|
181
|
+
<span class="ruby-identifier">after_hooks</span> = <span class="ruby-constant">Plugin</span>.<span class="ruby-identifier">after_hooks</span>(<span class="ruby-identifier">job</span>)
|
182
|
+
<span class="ruby-identifier">failure_hooks</span> = <span class="ruby-constant">Plugin</span>.<span class="ruby-identifier">failure_hooks</span>(<span class="ruby-identifier">job</span>)
|
183
|
+
|
184
|
+
<span class="ruby-keyword">begin</span>
|
185
|
+
<span class="ruby-comment"># Execute before_perform hook. Abort the job gracefully if</span>
|
186
|
+
<span class="ruby-comment"># Resque::DontPerform is raised.</span>
|
187
|
+
<span class="ruby-keyword">begin</span>
|
188
|
+
<span class="ruby-identifier">before_hooks</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hook</span><span class="ruby-operator">|</span>
|
189
|
+
<span class="ruby-identifier">job</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">hook</span>, *<span class="ruby-identifier">job_args</span>)
|
190
|
+
<span class="ruby-keyword">end</span>
|
191
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">DontPerform</span>
|
192
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span>
|
193
|
+
<span class="ruby-keyword">end</span>
|
194
|
+
|
195
|
+
<span class="ruby-comment"># Execute the job. Do it in an around_perform hook if available.</span>
|
196
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">around_hooks</span>.<span class="ruby-identifier">empty?</span>
|
197
|
+
<span class="ruby-identifier">job</span>.<span class="ruby-identifier">perform</span>(*<span class="ruby-identifier">job_args</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span>
|
198
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">status</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">present?</span>
|
199
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span>
|
200
|
+
<span class="ruby-keyword">end</span>
|
201
|
+
<span class="ruby-identifier">job_was_performed</span> = <span class="ruby-keyword">true</span>
|
202
|
+
<span class="ruby-keyword">else</span>
|
203
|
+
<span class="ruby-comment"># We want to nest all around_perform plugins, with the last one</span>
|
204
|
+
<span class="ruby-comment"># finally calling perform</span>
|
205
|
+
<span class="ruby-identifier">stack</span> = <span class="ruby-identifier">around_hooks</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-keyword">nil</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">last_hook</span>, <span class="ruby-identifier">hook</span><span class="ruby-operator">|</span>
|
206
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">last_hook</span>
|
207
|
+
<span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span>
|
208
|
+
<span class="ruby-identifier">job</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">hook</span>, *<span class="ruby-identifier">job_args</span>) { <span class="ruby-identifier">last_hook</span>.<span class="ruby-identifier">call</span> }
|
209
|
+
<span class="ruby-keyword">end</span>
|
210
|
+
<span class="ruby-keyword">else</span>
|
211
|
+
<span class="ruby-identifier">lambda</span> <span class="ruby-keyword">do</span>
|
212
|
+
<span class="ruby-identifier">job</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">hook</span>, *<span class="ruby-identifier">job_args</span>) <span class="ruby-keyword">do</span>
|
213
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">job</span>.<span class="ruby-identifier">perform</span>(*<span class="ruby-identifier">job_args</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span>
|
214
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span>.<span class="ruby-identifier">status</span> = <span class="ruby-identifier">status</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">present?</span>
|
215
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span>
|
216
|
+
<span class="ruby-keyword">end</span>
|
217
|
+
<span class="ruby-identifier">job_was_performed</span> = <span class="ruby-keyword">true</span>
|
218
|
+
<span class="ruby-identifier">result</span>
|
219
|
+
<span class="ruby-keyword">end</span>
|
220
|
+
<span class="ruby-keyword">end</span>
|
221
|
+
<span class="ruby-keyword">end</span>
|
222
|
+
<span class="ruby-keyword">end</span>
|
223
|
+
<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">call</span>
|
224
|
+
<span class="ruby-keyword">end</span>
|
225
|
+
|
226
|
+
<span class="ruby-comment"># Execute after_perform hook</span>
|
227
|
+
<span class="ruby-identifier">after_hooks</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hook</span><span class="ruby-operator">|</span>
|
228
|
+
<span class="ruby-identifier">job</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">hook</span>, *<span class="ruby-identifier">job_args</span>)
|
229
|
+
<span class="ruby-keyword">end</span>
|
230
|
+
|
231
|
+
<span class="ruby-comment"># Return true if the job was performed</span>
|
232
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">job_was_performed</span>
|
233
|
+
|
234
|
+
<span class="ruby-comment"># If an exception occurs during the job execution, look for an</span>
|
235
|
+
<span class="ruby-comment"># on_failure hook then re-raise.</span>
|
236
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Object</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
237
|
+
<span class="ruby-identifier">failure_hooks</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">hook</span><span class="ruby-operator">|</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">hook</span>, <span class="ruby-identifier">e</span>, *<span class="ruby-identifier">job_args</span>) }
|
238
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
|
239
|
+
<span class="ruby-keyword">end</span>
|
176
240
|
<span class="ruby-keyword">end</span></pre>
|
177
241
|
</div><!-- perform-source -->
|
178
242
|
|
@@ -67,12 +67,18 @@
|
|
67
67
|
|
68
68
|
<li><a href="#method-c-enqueue">::enqueue</a></li>
|
69
69
|
|
70
|
+
<li><a href="#method-c-new">::new</a></li>
|
71
|
+
|
72
|
+
<li><a href="#method-c-perform">::perform</a></li>
|
73
|
+
|
70
74
|
<li><a href="#method-i-counter">#counter</a></li>
|
71
75
|
|
72
76
|
<li><a href="#method-i-incr_counter">#incr_counter</a></li>
|
73
77
|
|
74
78
|
<li><a href="#method-i-name">#name</a></li>
|
75
79
|
|
80
|
+
<li><a href="#method-i-pause-21">#pause!</a></li>
|
81
|
+
|
76
82
|
<li><a href="#method-i-safe_perform-21">#safe_perform!</a></li>
|
77
83
|
|
78
84
|
<li><a href="#method-i-tick">#tick</a></li>
|
@@ -151,6 +157,28 @@
|
|
151
157
|
|
152
158
|
|
153
159
|
|
160
|
+
<!-- Attributes -->
|
161
|
+
<div id="attribute-method-details" class="method-section section">
|
162
|
+
<h3 class="section-header">Attributes</h3>
|
163
|
+
|
164
|
+
|
165
|
+
<div id="worker-attribute-method" class="method-detail">
|
166
|
+
<a name="worker"></a>
|
167
|
+
|
168
|
+
<div class="method-heading attribute-method-heading">
|
169
|
+
<span class="method-name">worker</span><span
|
170
|
+
class="attribute-access-type">[R]</span>
|
171
|
+
</div>
|
172
|
+
|
173
|
+
<div class="method-description">
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
</div>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
</div><!-- attribute-method-details -->
|
181
|
+
|
154
182
|
|
155
183
|
<!-- Methods -->
|
156
184
|
|
@@ -180,7 +208,7 @@ with existing resque jobs.</p>
|
|
180
208
|
|
181
209
|
<div class="method-source-code" id="enqueue-source">
|
182
210
|
<pre>
|
183
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line
|
211
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 9</span>
|
184
212
|
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">enqueue</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">options</span> = {})
|
185
213
|
<span class="ruby-identifier">uuid</span> = <span class="ruby-constant">Resque</span><span class="ruby-operator">::</span><span class="ruby-constant">Status</span>.<span class="ruby-identifier">create</span> <span class="ruby-value">:name</span> =<span class="ruby-operator">></span> <span class="ruby-node">"#{self.name}: #{options.inspect}"</span>
|
186
214
|
<span class="ruby-constant">Resque</span>.<span class="ruby-identifier">enqueue</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">uuid</span>, <span class="ruby-identifier">options</span>)
|
@@ -196,6 +224,85 @@ with existing resque jobs.</p>
|
|
196
224
|
</div><!-- enqueue-method -->
|
197
225
|
|
198
226
|
|
227
|
+
<div id="new-method" class="method-detail ">
|
228
|
+
<a name="method-c-new"></a>
|
229
|
+
|
230
|
+
|
231
|
+
<div class="method-heading">
|
232
|
+
<span class="method-name">new</span><span
|
233
|
+
class="method-args">(uuid, worker, options = {})</span>
|
234
|
+
<span class="method-click-advice">click to toggle source</span>
|
235
|
+
</div>
|
236
|
+
|
237
|
+
|
238
|
+
<div class="method-description">
|
239
|
+
|
240
|
+
<p>Create a new instance with <tt>uuid</tt> and <tt>options</tt> OVERRIDE to
|
241
|
+
add the worker attr</p>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
<div class="method-source-code" id="new-source">
|
246
|
+
<pre>
|
247
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 45</span>
|
248
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">uuid</span>, <span class="ruby-identifier">worker</span>, <span class="ruby-identifier">options</span> = {})
|
249
|
+
<span class="ruby-ivar">@uuid</span> = <span class="ruby-identifier">uuid</span>
|
250
|
+
<span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>
|
251
|
+
<span class="ruby-ivar">@worker</span> = <span class="ruby-identifier">worker</span>
|
252
|
+
<span class="ruby-keyword">end</span></pre>
|
253
|
+
</div><!-- new-source -->
|
254
|
+
|
255
|
+
</div>
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
</div><!-- new-method -->
|
261
|
+
|
262
|
+
|
263
|
+
<div id="perform-method" class="method-detail ">
|
264
|
+
<a name="method-c-perform"></a>
|
265
|
+
|
266
|
+
|
267
|
+
<div class="method-heading">
|
268
|
+
<span class="method-name">perform</span><span
|
269
|
+
class="method-args">(uuid=nil, options = {})</span>
|
270
|
+
<span class="method-click-advice">click to toggle source</span>
|
271
|
+
</div>
|
272
|
+
|
273
|
+
|
274
|
+
<div class="method-description">
|
275
|
+
|
276
|
+
<p>This is the method called by <a href="Worker.html">Resque::Worker</a> when
|
277
|
+
processing jobs. It creates a new instance of the job class and populates
|
278
|
+
it with the uuid and options.</p>
|
279
|
+
|
280
|
+
<p>You should not override this method, rather the <tt>perform</tt> instance
|
281
|
+
method. OVERRIDE to pass the block in order to set the worker status,
|
282
|
+
returns the worker object</p>
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
<div class="method-source-code" id="perform-source">
|
287
|
+
<pre>
|
288
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 57</span>
|
289
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">perform</span>(<span class="ruby-identifier">uuid</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {})
|
290
|
+
<span class="ruby-identifier">uuid</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Resque</span><span class="ruby-operator">::</span><span class="ruby-constant">Status</span>.<span class="ruby-identifier">generate_uuid</span>
|
291
|
+
<span class="ruby-identifier">worker</span> = <span class="ruby-keyword">yield</span>
|
292
|
+
<span class="ruby-identifier">instance</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">uuid</span>, <span class="ruby-identifier">worker</span>, <span class="ruby-identifier">options</span>)
|
293
|
+
<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">safe_perform!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span> }
|
294
|
+
<span class="ruby-identifier">instance</span>
|
295
|
+
<span class="ruby-keyword">end</span></pre>
|
296
|
+
</div><!-- perform-source -->
|
297
|
+
|
298
|
+
</div>
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
</div><!-- perform-method -->
|
304
|
+
|
305
|
+
|
199
306
|
</div><!-- public-class-method-details -->
|
200
307
|
|
201
308
|
<div id="public-instance-method-details" class="method-section section">
|
@@ -221,7 +328,7 @@ with existing resque jobs.</p>
|
|
221
328
|
|
222
329
|
<div class="method-source-code" id="counter-source">
|
223
330
|
<pre>
|
224
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line
|
331
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 99</span>
|
225
332
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">counter</span>(<span class="ruby-identifier">counter</span>)
|
226
333
|
<span class="ruby-constant">Resque</span><span class="ruby-operator">::</span><span class="ruby-constant">Status</span>.<span class="ruby-identifier">counter</span>(<span class="ruby-identifier">counter</span>, <span class="ruby-identifier">uuid</span>)
|
227
334
|
<span class="ruby-keyword">end</span></pre>
|
@@ -254,7 +361,7 @@ with existing resque jobs.</p>
|
|
254
361
|
|
255
362
|
<div class="method-source-code" id="incr_counter-source">
|
256
363
|
<pre>
|
257
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line
|
364
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 95</span>
|
258
365
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">incr_counter</span>(<span class="ruby-identifier">counter</span>)
|
259
366
|
<span class="ruby-constant">Resque</span><span class="ruby-operator">::</span><span class="ruby-constant">Status</span>.<span class="ruby-identifier">incr_counter</span>(<span class="ruby-identifier">counter</span>, <span class="ruby-identifier">uuid</span>)
|
260
367
|
<span class="ruby-keyword">end</span></pre>
|
@@ -287,7 +394,7 @@ with existing resque jobs.</p>
|
|
287
394
|
|
288
395
|
<div class="method-source-code" id="name-source">
|
289
396
|
<pre>
|
290
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line
|
397
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 91</span>
|
291
398
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">name</span>
|
292
399
|
<span class="ruby-node">"#{self.class.name}: #{options.inspect}"</span>
|
293
400
|
<span class="ruby-keyword">end</span></pre>
|
@@ -301,6 +408,42 @@ with existing resque jobs.</p>
|
|
301
408
|
</div><!-- name-method -->
|
302
409
|
|
303
410
|
|
411
|
+
<div id="pause-21-method" class="method-detail ">
|
412
|
+
<a name="method-i-pause-21"></a>
|
413
|
+
|
414
|
+
|
415
|
+
<div class="method-heading">
|
416
|
+
<span class="method-name">pause!</span><span
|
417
|
+
class="method-args">()</span>
|
418
|
+
<span class="method-click-advice">click to toggle source</span>
|
419
|
+
</div>
|
420
|
+
|
421
|
+
|
422
|
+
<div class="method-description">
|
423
|
+
|
424
|
+
<p>Pause the current job, setting the status to ‘paused’</p>
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
<div class="method-source-code" id="pause-21-source">
|
429
|
+
<pre>
|
430
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 36</span>
|
431
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">pause!</span>
|
432
|
+
<span class="ruby-identifier">set_status</span>({
|
433
|
+
<span class="ruby-string">'status'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'paused'</span>,
|
434
|
+
<span class="ruby-string">'message'</span> =<span class="ruby-operator">></span> <span class="ruby-node">"#{worker} paused at #{Time.now}"</span>
|
435
|
+
})
|
436
|
+
<span class="ruby-keyword">end</span></pre>
|
437
|
+
</div><!-- pause-21-source -->
|
438
|
+
|
439
|
+
</div>
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
</div><!-- pause-21-method -->
|
445
|
+
|
446
|
+
|
304
447
|
<div id="safe_perform-21-method" class="method-detail ">
|
305
448
|
<a name="method-i-safe_perform-21"></a>
|
306
449
|
|
@@ -323,11 +466,11 @@ work, it will set the status as failed and re-raise the error.</p>
|
|
323
466
|
|
324
467
|
<div class="method-source-code" id="safe_perform-21-source">
|
325
468
|
<pre>
|
326
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line
|
469
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 69</span>
|
327
470
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">safe_perform!</span>
|
328
471
|
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">should_kill?</span> <span class="ruby-operator">||</span> (<span class="ruby-identifier">status</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">killed?</span>)
|
329
472
|
<span class="ruby-identifier">set_status</span>({<span class="ruby-string">'status'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'working'</span>})
|
330
|
-
<span class="ruby-identifier">perform</span>
|
473
|
+
<span class="ruby-identifier">perform</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">status</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span> }
|
331
474
|
<span class="ruby-identifier">kill!</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">should_kill?</span>
|
332
475
|
<span class="ruby-identifier">completed</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">completed?</span>
|
333
476
|
<span class="ruby-identifier">on_success</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:on_success</span>)
|
@@ -377,10 +520,21 @@ This will kill the job if it has been added to the kill list with
|
|
377
520
|
|
378
521
|
<div class="method-source-code" id="tick-source">
|
379
522
|
<pre>
|
380
|
-
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line
|
523
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque_status/job_with_status.rb, line 19</span>
|
381
524
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">tick</span>(*<span class="ruby-identifier">messages</span>)
|
382
525
|
<span class="ruby-identifier">kill!</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">should_kill?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">killed?</span>
|
383
526
|
<span class="ruby-identifier">set_status</span>({<span class="ruby-string">'status'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'working'</span>}, *<span class="ruby-identifier">messages</span>)
|
527
|
+
<span class="ruby-comment"># check to see if the worker doing the job has been paused, pause the job if so</span>
|
528
|
+
<span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span> <span class="ruby-operator">&&</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span>.<span class="ruby-identifier">paused?</span>
|
529
|
+
<span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
|
530
|
+
<span class="ruby-comment"># Set the status to paused.</span>
|
531
|
+
<span class="ruby-comment"># May need to do this repeatedly because there could be workers in a chained job still doing work.</span>
|
532
|
+
<span class="ruby-identifier">pause!</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">paused?</span>
|
533
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">worker</span>.<span class="ruby-identifier">paused?</span>
|
534
|
+
<span class="ruby-identifier">sleep</span> <span class="ruby-value">60</span>
|
535
|
+
<span class="ruby-keyword">end</span>
|
536
|
+
<span class="ruby-identifier">set_status</span>({<span class="ruby-string">'status'</span> =<span class="ruby-operator">></span> <span class="ruby-string">'working'</span>}, *<span class="ruby-identifier">messages</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">status</span>.<span class="ruby-identifier">completed?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">paused?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">killed?</span>)
|
537
|
+
<span class="ruby-keyword">end</span>
|
384
538
|
<span class="ruby-keyword">end</span></pre>
|
385
539
|
</div><!-- tick-source -->
|
386
540
|
|