resque_ui 3.0.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/Gemfile +6 -0
- data/Gemfile.lock +102 -0
- data/History.txt +5 -0
- data/MIT-LICENSE +21 -0
- data/README.markdown +279 -0
- data/Rakefile +49 -0
- data/VERSION.yml +5 -0
- data/app/assets/images/idle.png +0 -0
- data/app/assets/images/poll.png +0 -0
- data/app/assets/images/working.png +0 -0
- data/app/assets/javascripts/resque/jquery-1.3.2.min.js +19 -0
- data/app/assets/javascripts/resque/jquery.relatize_date.js +95 -0
- data/app/assets/javascripts/resque/ranger.js +24 -0
- data/app/assets/stylesheets/resque/resque.css +93 -0
- data/app/assets/stylesheets/resque/resque_reset.css +48 -0
- data/app/controllers/resque_controller.rb +236 -0
- data/app/helpers/resque_helper.rb +107 -0
- data/app/views/layouts/resque.html.erb +39 -0
- data/app/views/resque/_key.html.erb +17 -0
- data/app/views/resque/_next_more.html.erb +10 -0
- data/app/views/resque/_queues.html.erb +52 -0
- data/app/views/resque/_status_styles.erb +98 -0
- data/app/views/resque/_workers.html.erb +110 -0
- data/app/views/resque/_working.html.erb +69 -0
- data/app/views/resque/delayed.html.erb +35 -0
- data/app/views/resque/delayed_timestamp.html.erb +26 -0
- data/app/views/resque/error.erb +1 -0
- data/app/views/resque/failed.html.erb +54 -0
- data/app/views/resque/overview.html.erb +4 -0
- data/app/views/resque/schedule.html.erb +96 -0
- data/app/views/resque/stats.html.erb +62 -0
- data/app/views/resque/status.html.erb +57 -0
- data/app/views/resque/statuses.html.erb +72 -0
- data/app/views/resque/workers.html.erb +1 -0
- data/lib/resque_ui/cap.rb +6 -0
- data/lib/resque_ui/cap_recipes.rb +106 -0
- data/lib/resque_ui/overrides/resque/failure/failure.rb +22 -0
- data/lib/resque_ui/overrides/resque/job.rb +12 -0
- data/lib/resque_ui/overrides/resque/resque.rb +8 -0
- data/lib/resque_ui/overrides/resque/worker.rb +230 -0
- data/lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb +58 -0
- data/lib/resque_ui/overrides/resque_status/chained_job_with_status.rb +24 -0
- data/lib/resque_ui/overrides/resque_status/job_with_status.rb +59 -0
- data/lib/resque_ui/overrides/resque_status/status.rb +53 -0
- data/lib/resque_ui.rb +26 -0
- data/lib/tasks/failure.rake +8 -0
- data/lib/tasks/scheduler.rake +11 -0
- data/lib/tasks/worker.rake +80 -0
- data/rdoc/Resque/ChainedJobWithStatus.html +284 -0
- data/rdoc/Resque/Failure/Base.html +229 -0
- data/rdoc/Resque/Failure.html +202 -0
- data/rdoc/Resque/Job.html +202 -0
- data/rdoc/Resque/JobWithStatus.html +410 -0
- data/rdoc/Resque/Status.html +368 -0
- data/rdoc/Resque/Worker.html +1104 -0
- data/rdoc/Resque.html +232 -0
- data/rdoc/ResqueScheduler.html +434 -0
- data/rdoc/ResqueUi/Cap.html +150 -0
- data/rdoc/ResqueUi/Engine.html +150 -0
- data/rdoc/ResqueUi.html +157 -0
- data/rdoc/created.rid +13 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +163 -0
- data/rdoc/js/darkfish.js +116 -0
- data/rdoc/js/jquery.js +32 -0
- data/rdoc/js/quicksearch.js +114 -0
- data/rdoc/js/thickbox-compressed.js +10 -0
- data/rdoc/lib/resque_overrides_rb.html +54 -0
- data/rdoc/lib/resque_scheduler_overrides_rb.html +52 -0
- data/rdoc/lib/resque_status_overrides_rb.html +52 -0
- data/rdoc/lib/resque_ui/cap_rb.html +52 -0
- data/rdoc/lib/resque_ui/cap_recipes_rb.html +58 -0
- data/rdoc/lib/resque_ui/engine_rb.html +52 -0
- data/rdoc/lib/resque_ui/overrides/resque/failure/failure_rb.html +54 -0
- data/rdoc/lib/resque_ui/overrides/resque/job_rb.html +52 -0
- data/rdoc/lib/resque_ui/overrides/resque/resque_rb.html +52 -0
- data/rdoc/lib/resque_ui/overrides/resque/worker_rb.html +54 -0
- data/rdoc/lib/resque_ui/overrides/resque_scheduler/resque_scheduler_rb.html +52 -0
- data/rdoc/lib/resque_ui/overrides/resque_status/chained_job_with_status_rb.html +52 -0
- data/rdoc/lib/resque_ui/overrides/resque_status/job_with_status_rb.html +52 -0
- data/rdoc/lib/resque_ui/overrides/resque_status/status_rb.html +52 -0
- data/rdoc/lib/resque_ui/resque_ui_rb.html +52 -0
- data/rdoc/lib/resque_ui/tasks_rb.html +64 -0
- data/rdoc/lib/resque_ui_rb.html +76 -0
- data/rdoc/rdoc.css +763 -0
- data/resque_ui.gemspec +153 -0
- data/test/resque_ui_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +205 -0
|
@@ -0,0 +1,1104 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
|
7
|
+
|
|
8
|
+
<title>Class: Resque::Worker</title>
|
|
9
|
+
|
|
10
|
+
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
|
|
11
|
+
|
|
12
|
+
<script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
|
|
13
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
|
|
14
|
+
<script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
|
|
15
|
+
<script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>
|
|
16
|
+
|
|
17
|
+
</head>
|
|
18
|
+
<body id="top" class="class">
|
|
19
|
+
|
|
20
|
+
<div id="metadata">
|
|
21
|
+
<div id="home-metadata">
|
|
22
|
+
<div id="home-section" class="section">
|
|
23
|
+
<h3 class="section-header">
|
|
24
|
+
<a href="../index.html">Home</a>
|
|
25
|
+
<a href="../index.html#classes">Classes</a>
|
|
26
|
+
<a href="../index.html#methods">Methods</a>
|
|
27
|
+
</h3>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div id="file-metadata">
|
|
32
|
+
<div id="file-list-section" class="section">
|
|
33
|
+
<h3 class="section-header">In Files</h3>
|
|
34
|
+
<div class="section-body">
|
|
35
|
+
<ul>
|
|
36
|
+
|
|
37
|
+
<li><a href="../lib/resque_ui/overrides/resque/worker_rb.html?TB_iframe=true&height=550&width=785"
|
|
38
|
+
class="thickbox" title="lib/resque_ui/overrides/resque/worker.rb">lib/resque_ui/overrides/resque/worker.rb</a></li>
|
|
39
|
+
|
|
40
|
+
</ul>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div id="class-metadata">
|
|
48
|
+
|
|
49
|
+
<!-- Parent Class -->
|
|
50
|
+
<div id="parent-class-section" class="section">
|
|
51
|
+
<h3 class="section-header">Parent</h3>
|
|
52
|
+
|
|
53
|
+
<p class="link">Object</p>
|
|
54
|
+
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<!-- Method Quickref -->
|
|
64
|
+
<div id="method-list-section" class="section">
|
|
65
|
+
<h3 class="section-header">Methods</h3>
|
|
66
|
+
<ul class="link-list">
|
|
67
|
+
|
|
68
|
+
<li><a href="#method-c-start">::start</a></li>
|
|
69
|
+
|
|
70
|
+
<li><a href="#method-c-working">::working</a></li>
|
|
71
|
+
|
|
72
|
+
<li><a href="#method-i-all_workers_in_pid_working">#all_workers_in_pid_working</a></li>
|
|
73
|
+
|
|
74
|
+
<li><a href="#method-i-id">#id</a></li>
|
|
75
|
+
|
|
76
|
+
<li><a href="#method-i-ip">#ip</a></li>
|
|
77
|
+
|
|
78
|
+
<li><a href="#method-i-local_ip">#local_ip</a></li>
|
|
79
|
+
|
|
80
|
+
<li><a href="#method-i-pid">#pid</a></li>
|
|
81
|
+
|
|
82
|
+
<li><a href="#method-i-prune_dead_workers">#prune_dead_workers</a></li>
|
|
83
|
+
|
|
84
|
+
<li><a href="#method-i-queue">#queue</a></li>
|
|
85
|
+
|
|
86
|
+
<li><a href="#method-i-queues">#queues</a></li>
|
|
87
|
+
|
|
88
|
+
<li><a href="#method-i-queues_in_pid">#queues_in_pid</a></li>
|
|
89
|
+
|
|
90
|
+
<li><a href="#method-i-quit">#quit</a></li>
|
|
91
|
+
|
|
92
|
+
<li><a href="#method-i-register_signal_handlers">#register_signal_handlers</a></li>
|
|
93
|
+
|
|
94
|
+
<li><a href="#method-i-restart">#restart</a></li>
|
|
95
|
+
|
|
96
|
+
<li><a href="#method-i-shutdown">#shutdown</a></li>
|
|
97
|
+
|
|
98
|
+
<li><a href="#method-i-startup">#startup</a></li>
|
|
99
|
+
|
|
100
|
+
<li><a href="#method-i-status">#status</a></li>
|
|
101
|
+
|
|
102
|
+
<li><a href="#method-i-status-3D">#status=</a></li>
|
|
103
|
+
|
|
104
|
+
<li><a href="#method-i-thread">#thread</a></li>
|
|
105
|
+
|
|
106
|
+
<li><a href="#method-i-to_s">#to_s</a></li>
|
|
107
|
+
|
|
108
|
+
<li><a href="#method-i-work">#work</a></li>
|
|
109
|
+
|
|
110
|
+
<li><a href="#method-i-worker_pids">#worker_pids</a></li>
|
|
111
|
+
|
|
112
|
+
<li><a href="#method-i-workers_in_pid">#workers_in_pid</a></li>
|
|
113
|
+
|
|
114
|
+
</ul>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div id="project-metadata">
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
<div id="classindex-section" class="section project-section">
|
|
126
|
+
<h3 class="section-header">Class/Module Index
|
|
127
|
+
<span class="search-toggle"><img src="../images/find.png"
|
|
128
|
+
height="16" width="16" alt="[+]"
|
|
129
|
+
title="show/hide quicksearch" /></span></h3>
|
|
130
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
|
131
|
+
<fieldset>
|
|
132
|
+
<legend>Quicksearch</legend>
|
|
133
|
+
<input type="text" name="quicksearch" value=""
|
|
134
|
+
class="quicksearch-field" />
|
|
135
|
+
</fieldset>
|
|
136
|
+
</form>
|
|
137
|
+
|
|
138
|
+
<ul class="link-list">
|
|
139
|
+
|
|
140
|
+
<li><a href="../Resque.html">Resque</a></li>
|
|
141
|
+
|
|
142
|
+
<li><a href="../Resque/ChainedJobWithStatus.html">Resque::ChainedJobWithStatus</a></li>
|
|
143
|
+
|
|
144
|
+
<li><a href="../Resque/Failure.html">Resque::Failure</a></li>
|
|
145
|
+
|
|
146
|
+
<li><a href="../Resque/Job.html">Resque::Job</a></li>
|
|
147
|
+
|
|
148
|
+
<li><a href="../Resque/JobWithStatus.html">Resque::JobWithStatus</a></li>
|
|
149
|
+
|
|
150
|
+
<li><a href="../Resque/Status.html">Resque::Status</a></li>
|
|
151
|
+
|
|
152
|
+
<li><a href="../Resque/Worker.html">Resque::Worker</a></li>
|
|
153
|
+
|
|
154
|
+
<li><a href="../ResqueUi.html">ResqueUi</a></li>
|
|
155
|
+
|
|
156
|
+
<li><a href="../ResqueUi/Cap.html">ResqueUi::Cap</a></li>
|
|
157
|
+
|
|
158
|
+
<li><a href="../ResqueUi/Engine.html">ResqueUi::Engine</a></li>
|
|
159
|
+
|
|
160
|
+
<li><a href="../ResqueScheduler.html">ResqueScheduler</a></li>
|
|
161
|
+
|
|
162
|
+
</ul>
|
|
163
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<div id="documentation">
|
|
171
|
+
<h1 class="class">Resque::Worker</h1>
|
|
172
|
+
|
|
173
|
+
<div id="description" class="description">
|
|
174
|
+
|
|
175
|
+
</div><!-- description -->
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
<div id="5Buntitled-5D" class="documentation-section">
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
<!-- Methods -->
|
|
190
|
+
|
|
191
|
+
<div id="public-class-method-details" class="method-section section">
|
|
192
|
+
<h3 class="section-header">Public Class Methods</h3>
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
<div id="start-method" class="method-detail ">
|
|
196
|
+
<a name="method-c-start"></a>
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
<div class="method-heading">
|
|
200
|
+
<span class="method-name">start</span><span
|
|
201
|
+
class="method-args">(ips, queues)</span>
|
|
202
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
<div class="method-description">
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
<div class="method-source-code" id="start-source">
|
|
213
|
+
<pre>
|
|
214
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 207</span>
|
|
215
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">ips</span>, <span class="ruby-identifier">queues</span>)
|
|
216
|
+
<span class="ruby-keyword">if</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">env</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/development|test/</span>
|
|
217
|
+
<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">queues</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">queue</span><span class="ruby-operator">|</span> <span class="ruby-identifier">system</span>(<span class="ruby-node">"rake QUEUE=#{queue} resque:work"</span>) }
|
|
218
|
+
<span class="ruby-keyword">else</span>
|
|
219
|
+
<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">queues</span>, <span class="ruby-identifier">ips</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">queue</span>, <span class="ruby-identifier">ip_list</span><span class="ruby-operator">|</span> <span class="ruby-identifier">system</span>(<span class="ruby-node">"cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:work host=#{ip_list} queue=#{queue}"</span>) }
|
|
220
|
+
<span class="ruby-keyword">end</span>
|
|
221
|
+
<span class="ruby-keyword">end</span></pre>
|
|
222
|
+
</div><!-- start-source -->
|
|
223
|
+
|
|
224
|
+
</div>
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
</div><!-- start-method -->
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
<div id="working-method" class="method-detail ">
|
|
233
|
+
<a name="method-c-working"></a>
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
<div class="method-heading">
|
|
237
|
+
<span class="method-name">working</span><span
|
|
238
|
+
class="method-args">()</span>
|
|
239
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
<div class="method-description">
|
|
244
|
+
|
|
245
|
+
<p>logic for mappged_mget changed where it returns keys with nil values in
|
|
246
|
+
latest redis gem.</p>
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
<div class="method-source-code" id="working-source">
|
|
251
|
+
<pre>
|
|
252
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 181</span>
|
|
253
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">working</span>
|
|
254
|
+
<span class="ruby-identifier">names</span> = <span class="ruby-identifier">all</span>
|
|
255
|
+
<span class="ruby-keyword">return</span> [] <span class="ruby-keyword">unless</span> <span class="ruby-identifier">names</span>.<span class="ruby-identifier">any?</span>
|
|
256
|
+
<span class="ruby-identifier">names</span>.<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-node">"worker:#{name}"</span> }
|
|
257
|
+
<span class="ruby-identifier">redis</span>.<span class="ruby-identifier">mapped_mget</span>(*<span class="ruby-identifier">names</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
|
258
|
+
<span class="ruby-identifier">find</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-string">"worker:"</span>, <span class="ruby-string">''</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
|
|
259
|
+
<span class="ruby-keyword">end</span>.<span class="ruby-identifier">compact</span>
|
|
260
|
+
<span class="ruby-keyword">end</span></pre>
|
|
261
|
+
</div><!-- working-source -->
|
|
262
|
+
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
</div><!-- working-method -->
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
</div><!-- public-class-method-details -->
|
|
272
|
+
|
|
273
|
+
<div id="public-instance-method-details" class="method-section section">
|
|
274
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
<div id="all_workers_in_pid_working-method" class="method-detail ">
|
|
278
|
+
<a name="method-i-all_workers_in_pid_working"></a>
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
<div class="method-heading">
|
|
282
|
+
<span class="method-name">all_workers_in_pid_working</span><span
|
|
283
|
+
class="method-args">()</span>
|
|
284
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
<div class="method-description">
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
<div class="method-source-code" id="all_workers_in_pid_working-source">
|
|
295
|
+
<pre>
|
|
296
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 99</span>
|
|
297
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">all_workers_in_pid_working</span>
|
|
298
|
+
<span class="ruby-identifier">workers_in_pid</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">hash</span> = <span class="ruby-identifier">w</span>.<span class="ruby-identifier">processing</span>) <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">hash</span>.<span class="ruby-identifier">empty?</span> }
|
|
299
|
+
<span class="ruby-keyword">end</span></pre>
|
|
300
|
+
</div><!-- all_workers_in_pid_working-source -->
|
|
301
|
+
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
</div><!-- all_workers_in_pid_working-method -->
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
<div id="id-method" class="method-detail method-alias">
|
|
311
|
+
<a name="method-i-id"></a>
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
<div class="method-heading">
|
|
315
|
+
<span class="method-name">id</span><span
|
|
316
|
+
class="method-args">()</span>
|
|
317
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
<div class="method-description">
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
</div>
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
<div class="aliases">
|
|
333
|
+
Alias for: <a href="Worker.html#method-i-to_s">to_s</a>
|
|
334
|
+
</div>
|
|
335
|
+
|
|
336
|
+
</div><!-- id-method -->
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
<div id="ip-method" class="method-detail ">
|
|
340
|
+
<a name="method-i-ip"></a>
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
<div class="method-heading">
|
|
344
|
+
<span class="method-name">ip</span><span
|
|
345
|
+
class="method-args">()</span>
|
|
346
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
<div class="method-description">
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
<div class="method-source-code" id="ip-source">
|
|
357
|
+
<pre>
|
|
358
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 41</span>
|
|
359
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">ip</span>
|
|
360
|
+
<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">':'</span>).<span class="ruby-identifier">first</span>[<span class="ruby-regexp">/\b(?:\d{1,3}\.){3}\d{1,3}\b/</span>]
|
|
361
|
+
<span class="ruby-keyword">end</span></pre>
|
|
362
|
+
</div><!-- ip-source -->
|
|
363
|
+
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
</div><!-- ip-method -->
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
<div id="local_ip-method" class="method-detail ">
|
|
373
|
+
<a name="method-i-local_ip"></a>
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
<div class="method-heading">
|
|
377
|
+
<span class="method-name">local_ip</span><span
|
|
378
|
+
class="method-args">()</span>
|
|
379
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
380
|
+
</div>
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
<div class="method-description">
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
<div class="method-source-code" id="local_ip-source">
|
|
390
|
+
<pre>
|
|
391
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 6</span>
|
|
392
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">local_ip</span>
|
|
393
|
+
<span class="ruby-identifier">orig</span>, <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span> = <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>, <span class="ruby-keyword">true</span> <span class="ruby-comment"># turn off reverse DNS resolution temporarily</span>
|
|
394
|
+
|
|
395
|
+
<span class="ruby-constant">UDPSocket</span>.<span class="ruby-identifier">open</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
|
|
396
|
+
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">connect</span> <span class="ruby-string">'64.233.187.99'</span>, <span class="ruby-value">1</span>
|
|
397
|
+
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">addr</span>.<span class="ruby-identifier">last</span>
|
|
398
|
+
<span class="ruby-keyword">end</span>
|
|
399
|
+
<span class="ruby-keyword">ensure</span>
|
|
400
|
+
<span class="ruby-constant">Socket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span> = <span class="ruby-identifier">orig</span>
|
|
401
|
+
<span class="ruby-keyword">end</span></pre>
|
|
402
|
+
</div><!-- local_ip-source -->
|
|
403
|
+
|
|
404
|
+
</div>
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
</div><!-- local_ip-method -->
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
<div id="pid-method" class="method-detail ">
|
|
413
|
+
<a name="method-i-pid"></a>
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
<div class="method-heading">
|
|
417
|
+
<span class="method-name">pid</span><span
|
|
418
|
+
class="method-args">()</span>
|
|
419
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
420
|
+
</div>
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
<div class="method-description">
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
<div class="method-source-code" id="pid-source">
|
|
430
|
+
<pre>
|
|
431
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 25</span>
|
|
432
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">pid</span>
|
|
433
|
+
<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">':'</span>).<span class="ruby-identifier">second</span>
|
|
434
|
+
<span class="ruby-keyword">end</span></pre>
|
|
435
|
+
</div><!-- pid-source -->
|
|
436
|
+
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
</div><!-- pid-method -->
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
<div id="prune_dead_workers-method" class="method-detail ">
|
|
446
|
+
<a name="method-i-prune_dead_workers"></a>
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
<div class="method-heading">
|
|
450
|
+
<span class="method-name">prune_dead_workers</span><span
|
|
451
|
+
class="method-args">()</span>
|
|
452
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
453
|
+
</div>
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
<div class="method-description">
|
|
457
|
+
|
|
458
|
+
<p>Looks for any workers which should be running on this server and, if
|
|
459
|
+
they’re not, removes them from Redis.</p>
|
|
460
|
+
|
|
461
|
+
<p>This is a form of garbage collection. If a server is killed by a hard
|
|
462
|
+
shutdown, power failure, or something else beyond our control, the <a
|
|
463
|
+
href="../Resque.html">Resque</a> workers will not die gracefully and
|
|
464
|
+
therefor will leave stale state information in Redis.</p>
|
|
465
|
+
|
|
466
|
+
<p>By checking the current Redis state against the actual environment, we can
|
|
467
|
+
determine if Redis is old and clean it up a bit.</p>
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
<div class="method-source-code" id="prune_dead_workers-source">
|
|
472
|
+
<pre>
|
|
473
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 89</span>
|
|
474
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">prune_dead_workers</span>
|
|
475
|
+
<span class="ruby-constant">Worker</span>.<span class="ruby-identifier">all</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">worker</span><span class="ruby-operator">|</span>
|
|
476
|
+
<span class="ruby-identifier">host</span>, <span class="ruby-identifier">pid</span>, <span class="ruby-identifier">thread</span>, <span class="ruby-identifier">queues</span> = <span class="ruby-identifier">worker</span>.<span class="ruby-identifier">id</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">':'</span>)
|
|
477
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">host</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">hostname</span>)
|
|
478
|
+
<span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">worker_pids</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">pid</span>)
|
|
479
|
+
<span class="ruby-identifier">log!</span> <span class="ruby-node">"Pruning dead worker: #{worker}"</span>
|
|
480
|
+
<span class="ruby-identifier">worker</span>.<span class="ruby-identifier">unregister_worker</span>
|
|
481
|
+
<span class="ruby-keyword">end</span>
|
|
482
|
+
<span class="ruby-keyword">end</span></pre>
|
|
483
|
+
</div><!-- prune_dead_workers-source -->
|
|
484
|
+
|
|
485
|
+
</div>
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
</div><!-- prune_dead_workers-method -->
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
<div id="queue-method" class="method-detail ">
|
|
494
|
+
<a name="method-i-queue"></a>
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
<div class="method-heading">
|
|
498
|
+
<span class="method-name">queue</span><span
|
|
499
|
+
class="method-args">()</span>
|
|
500
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
501
|
+
</div>
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
<div class="method-description">
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
<div class="method-source-code" id="queue-source">
|
|
511
|
+
<pre>
|
|
512
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 33</span>
|
|
513
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">queue</span>
|
|
514
|
+
<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">':'</span>).<span class="ruby-identifier">last</span>
|
|
515
|
+
<span class="ruby-keyword">end</span></pre>
|
|
516
|
+
</div><!-- queue-source -->
|
|
517
|
+
|
|
518
|
+
</div>
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
</div><!-- queue-method -->
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
<div id="queues-method" class="method-detail ">
|
|
527
|
+
<a name="method-i-queues"></a>
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
<div class="method-heading">
|
|
531
|
+
<span class="method-name">queues</span><span
|
|
532
|
+
class="method-args">()</span>
|
|
533
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
534
|
+
</div>
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
<div class="method-description">
|
|
538
|
+
|
|
539
|
+
<p>OVERRIDE for multithreaded workers</p>
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
<div class="method-source-code" id="queues-source">
|
|
544
|
+
<pre>
|
|
545
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 50</span>
|
|
546
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">queues</span>
|
|
547
|
+
<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:queues</span>] <span class="ruby-operator">==</span> <span class="ruby-string">"*"</span> <span class="ruby-operator">?</span> <span class="ruby-constant">Resque</span>.<span class="ruby-identifier">queues</span>.<span class="ruby-identifier">sort</span> <span class="ruby-operator">:</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:queues</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">','</span>)
|
|
548
|
+
<span class="ruby-keyword">end</span></pre>
|
|
549
|
+
</div><!-- queues-source -->
|
|
550
|
+
|
|
551
|
+
</div>
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
</div><!-- queues-method -->
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
<div id="queues_in_pid-method" class="method-detail ">
|
|
560
|
+
<a name="method-i-queues_in_pid"></a>
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
<div class="method-heading">
|
|
564
|
+
<span class="method-name">queues_in_pid</span><span
|
|
565
|
+
class="method-args">()</span>
|
|
566
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
567
|
+
</div>
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
<div class="method-description">
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
<div class="method-source-code" id="queues_in_pid-source">
|
|
577
|
+
<pre>
|
|
578
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 45</span>
|
|
579
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">queues_in_pid</span>
|
|
580
|
+
<span class="ruby-identifier">workers_in_pid</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span> <span class="ruby-identifier">w</span>.<span class="ruby-identifier">queue</span> }
|
|
581
|
+
<span class="ruby-keyword">end</span></pre>
|
|
582
|
+
</div><!-- queues_in_pid-source -->
|
|
583
|
+
|
|
584
|
+
</div>
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
</div><!-- queues_in_pid-method -->
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
<div id="quit-method" class="method-detail ">
|
|
593
|
+
<a name="method-i-quit"></a>
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
<div class="method-heading">
|
|
597
|
+
<span class="method-name">quit</span><span
|
|
598
|
+
class="method-args">()</span>
|
|
599
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
600
|
+
</div>
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
<div class="method-description">
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
<div class="method-source-code" id="quit-source">
|
|
610
|
+
<pre>
|
|
611
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 215</span>
|
|
612
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">quit</span>
|
|
613
|
+
<span class="ruby-keyword">if</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">env</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/development|test/</span>
|
|
614
|
+
<span class="ruby-identifier">system</span>(<span class="ruby-node">"kill -INT #{self.pid}"</span>)
|
|
615
|
+
<span class="ruby-keyword">else</span>
|
|
616
|
+
<span class="ruby-identifier">system</span>(<span class="ruby-node">"cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:quit_worker pid=#{self.pid} host=#{self.ip}"</span>)
|
|
617
|
+
<span class="ruby-keyword">end</span>
|
|
618
|
+
<span class="ruby-keyword">end</span></pre>
|
|
619
|
+
</div><!-- quit-source -->
|
|
620
|
+
|
|
621
|
+
</div>
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
</div><!-- quit-method -->
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
<div id="register_signal_handlers-method" class="method-detail ">
|
|
630
|
+
<a name="method-i-register_signal_handlers"></a>
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
<div class="method-heading">
|
|
634
|
+
<span class="method-name">register_signal_handlers</span><span
|
|
635
|
+
class="method-args">()</span>
|
|
636
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
637
|
+
</div>
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
<div class="method-description">
|
|
641
|
+
|
|
642
|
+
<p>Jruby won’t allow you to trap the QUIT signal, so we’re changing the
|
|
643
|
+
INT signal to replace it for Jruby.</p>
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
<div class="method-source-code" id="register_signal_handlers-source">
|
|
648
|
+
<pre>
|
|
649
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 104</span>
|
|
650
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">register_signal_handlers</span>
|
|
651
|
+
<span class="ruby-identifier">trap</span>(<span class="ruby-string">'TERM'</span>) { <span class="ruby-identifier">shutdown!</span> }
|
|
652
|
+
<span class="ruby-identifier">trap</span>(<span class="ruby-string">'INT'</span>) { <span class="ruby-identifier">shutdown</span> }
|
|
653
|
+
|
|
654
|
+
<span class="ruby-keyword">begin</span>
|
|
655
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-identifier">trap</span>(<span class="ruby-string">'QUIT'</span>) { <span class="ruby-identifier">shutdown</span> }
|
|
656
|
+
<span class="ruby-identifier">warn</span> <span class="ruby-string">"Signal QUIT not supported."</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span>
|
|
657
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-identifier">trap</span>(<span class="ruby-string">'USR1'</span>) { <span class="ruby-identifier">kill_child</span> }
|
|
658
|
+
<span class="ruby-identifier">warn</span> <span class="ruby-string">"Signal USR1 not supported."</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span>
|
|
659
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-identifier">trap</span>(<span class="ruby-string">'USR2'</span>) { <span class="ruby-identifier">pause_processing</span> }
|
|
660
|
+
<span class="ruby-identifier">warn</span> <span class="ruby-string">"Signal USR2 not supported."</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span>
|
|
661
|
+
<span class="ruby-identifier">s</span> = <span class="ruby-identifier">trap</span>(<span class="ruby-string">'CONT'</span>) { <span class="ruby-identifier">unpause_processing</span> }
|
|
662
|
+
<span class="ruby-identifier">warn</span> <span class="ruby-string">"Signal CONT not supported."</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">s</span>
|
|
663
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">ArgumentError</span>
|
|
664
|
+
<span class="ruby-identifier">warn</span> <span class="ruby-string">"Signals QUIT, USR1, USR2, and/or CONT not supported."</span>
|
|
665
|
+
<span class="ruby-keyword">end</span>
|
|
666
|
+
<span class="ruby-keyword">end</span></pre>
|
|
667
|
+
</div><!-- register_signal_handlers-source -->
|
|
668
|
+
|
|
669
|
+
</div>
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
</div><!-- register_signal_handlers-method -->
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
<div id="restart-method" class="method-detail ">
|
|
678
|
+
<a name="method-i-restart"></a>
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
<div class="method-heading">
|
|
682
|
+
<span class="method-name">restart</span><span
|
|
683
|
+
class="method-args">()</span>
|
|
684
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
685
|
+
</div>
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
<div class="method-description">
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
<div class="method-source-code" id="restart-source">
|
|
695
|
+
<pre>
|
|
696
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 223</span>
|
|
697
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">restart</span>
|
|
698
|
+
<span class="ruby-identifier">queues</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">queues_in_pid</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">'#'</span>)
|
|
699
|
+
<span class="ruby-identifier">quit</span>
|
|
700
|
+
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">start</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">ip</span>, <span class="ruby-identifier">queues</span>)
|
|
701
|
+
<span class="ruby-keyword">end</span></pre>
|
|
702
|
+
</div><!-- restart-source -->
|
|
703
|
+
|
|
704
|
+
</div>
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
</div><!-- restart-method -->
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
<div id="shutdown-method" class="method-detail ">
|
|
713
|
+
<a name="method-i-shutdown"></a>
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
<div class="method-heading">
|
|
717
|
+
<span class="method-name">shutdown</span><span
|
|
718
|
+
class="method-args">()</span>
|
|
719
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
720
|
+
</div>
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
<div class="method-description">
|
|
724
|
+
|
|
725
|
+
<pre>Schedule this worker for shutdown. Will finish processing the
|
|
726
|
+
current job.</pre>
|
|
727
|
+
|
|
728
|
+
<p>OVERRIDE for multithreaded workers</p>
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
<div class="method-source-code" id="shutdown-source">
|
|
733
|
+
<pre>
|
|
734
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 73</span>
|
|
735
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">shutdown</span>
|
|
736
|
+
<span class="ruby-identifier">log</span> <span class="ruby-string">'Exiting...'</span>
|
|
737
|
+
<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">t</span>[<span class="ruby-value">:shutdown</span>] = <span class="ruby-keyword">true</span> }
|
|
738
|
+
<span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword">true</span>
|
|
739
|
+
<span class="ruby-keyword">end</span></pre>
|
|
740
|
+
</div><!-- shutdown-source -->
|
|
741
|
+
|
|
742
|
+
</div>
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
</div><!-- shutdown-method -->
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
<div id="startup-method" class="method-detail ">
|
|
751
|
+
<a name="method-i-startup"></a>
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
<div class="method-heading">
|
|
755
|
+
<span class="method-name">startup</span><span
|
|
756
|
+
class="method-args">()</span>
|
|
757
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
758
|
+
</div>
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
<div class="method-description">
|
|
762
|
+
|
|
763
|
+
<pre>Runs all the methods needed when a worker begins its lifecycle.</pre>
|
|
764
|
+
|
|
765
|
+
<p>OVERRIDE for multithreaded workers</p>
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
<div class="method-source-code" id="startup-source">
|
|
770
|
+
<pre>
|
|
771
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 56</span>
|
|
772
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">startup</span>
|
|
773
|
+
<span class="ruby-identifier">enable_gc_optimizations</span>
|
|
774
|
+
<span class="ruby-keyword">if</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">main</span>
|
|
775
|
+
<span class="ruby-identifier">register_signal_handlers</span>
|
|
776
|
+
<span class="ruby-identifier">prune_dead_workers</span>
|
|
777
|
+
<span class="ruby-keyword">end</span>
|
|
778
|
+
<span class="ruby-identifier">run_hook</span> <span class="ruby-value">:before_first_fork</span>
|
|
779
|
+
<span class="ruby-identifier">register_worker</span>
|
|
780
|
+
|
|
781
|
+
<span class="ruby-comment"># Fix buffering so we can `rake resque:work > resque.log` and</span>
|
|
782
|
+
<span class="ruby-comment"># get output from the child in there.</span>
|
|
783
|
+
<span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword">true</span>
|
|
784
|
+
<span class="ruby-keyword">end</span></pre>
|
|
785
|
+
</div><!-- startup-source -->
|
|
786
|
+
|
|
787
|
+
</div>
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
</div><!-- startup-method -->
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
<div id="status-method" class="method-detail ">
|
|
796
|
+
<a name="method-i-status"></a>
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
<div class="method-heading">
|
|
800
|
+
<span class="method-name">status</span><span
|
|
801
|
+
class="method-args">()</span>
|
|
802
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
803
|
+
</div>
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
<div class="method-description">
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
<div class="method-source-code" id="status-source">
|
|
813
|
+
<pre>
|
|
814
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 203</span>
|
|
815
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">status</span>
|
|
816
|
+
<span class="ruby-identifier">job</span>[<span class="ruby-string">'status'</span>]
|
|
817
|
+
<span class="ruby-keyword">end</span></pre>
|
|
818
|
+
</div><!-- status-source -->
|
|
819
|
+
|
|
820
|
+
</div>
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
</div><!-- status-method -->
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
<div id="status-3D-method" class="method-detail ">
|
|
829
|
+
<a name="method-i-status-3D"></a>
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
<div class="method-heading">
|
|
833
|
+
<span class="method-name">status=</span><span
|
|
834
|
+
class="method-args">(status)</span>
|
|
835
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
836
|
+
</div>
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
<div class="method-description">
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
<div class="method-source-code" id="status-3D-source">
|
|
846
|
+
<pre>
|
|
847
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 198</span>
|
|
848
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">status=</span>(<span class="ruby-identifier">status</span>)
|
|
849
|
+
<span class="ruby-identifier">data</span> = <span class="ruby-identifier">encode</span>(<span class="ruby-identifier">job</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-string">'status'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">status</span>))
|
|
850
|
+
<span class="ruby-identifier">redis</span>.<span class="ruby-identifier">set</span>(<span class="ruby-node">"worker:#{self}"</span>, <span class="ruby-identifier">data</span>)
|
|
851
|
+
<span class="ruby-keyword">end</span></pre>
|
|
852
|
+
</div><!-- status-3D-source -->
|
|
853
|
+
|
|
854
|
+
</div>
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
</div><!-- status-3D-method -->
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
<div id="thread-method" class="method-detail ">
|
|
863
|
+
<a name="method-i-thread"></a>
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
<div class="method-heading">
|
|
867
|
+
<span class="method-name">thread</span><span
|
|
868
|
+
class="method-args">()</span>
|
|
869
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
870
|
+
</div>
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
<div class="method-description">
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
<div class="method-source-code" id="thread-source">
|
|
880
|
+
<pre>
|
|
881
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 29</span>
|
|
882
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">thread</span>
|
|
883
|
+
<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">':'</span>).<span class="ruby-identifier">third</span>
|
|
884
|
+
<span class="ruby-keyword">end</span></pre>
|
|
885
|
+
</div><!-- thread-source -->
|
|
886
|
+
|
|
887
|
+
</div>
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
</div><!-- thread-method -->
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
<div id="to_s-method" class="method-detail ">
|
|
896
|
+
<a name="method-i-to_s"></a>
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
<div class="method-heading">
|
|
900
|
+
<span class="method-name">to_s</span><span
|
|
901
|
+
class="method-args">()</span>
|
|
902
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
903
|
+
</div>
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
<div class="method-description">
|
|
907
|
+
|
|
908
|
+
<p>The string representation is the same as the id for this worker instance.
|
|
909
|
+
Can be used with `Worker.find`.</p>
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
<div class="method-source-code" id="to_s-source">
|
|
914
|
+
<pre>
|
|
915
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 19</span>
|
|
916
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_s</span>
|
|
917
|
+
<span class="ruby-ivar">@to_s</span> <span class="ruby-operator">||</span> <span class="ruby-node">"#{hostname}(#{local_ip}):#{Process.pid}:#{Thread.current.object_id}:#{Thread.current[:queues]}"</span>
|
|
918
|
+
<span class="ruby-keyword">end</span></pre>
|
|
919
|
+
</div><!-- to_s-source -->
|
|
920
|
+
|
|
921
|
+
</div>
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
<div class="aliases">
|
|
925
|
+
Also aliased as: <a href="Worker.html#method-i-id">id</a>
|
|
926
|
+
</div>
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
</div><!-- to_s-method -->
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
<div id="work-method" class="method-detail ">
|
|
934
|
+
<a name="method-i-work"></a>
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
<div class="method-heading">
|
|
938
|
+
<span class="method-name">work</span><span
|
|
939
|
+
class="method-args">(interval = 5, &block)</span>
|
|
940
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
941
|
+
</div>
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
<div class="method-description">
|
|
945
|
+
|
|
946
|
+
<pre>This is the main workhorse method. Called on a Worker instance,
|
|
947
|
+
it begins the worker life cycle.
|
|
948
|
+
|
|
949
|
+
The following events occur during a worker's life cycle:
|
|
950
|
+
|
|
951
|
+
1. Startup: Signals are registered, dead workers are pruned,
|
|
952
|
+
and this worker is registered.
|
|
953
|
+
2. Work loop: Jobs are pulled from a queue and processed.
|
|
954
|
+
3. Teardown: This worker is unregistered.
|
|
955
|
+
|
|
956
|
+
Can be passed an integer representing the polling frequency.
|
|
957
|
+
The default is 5 seconds, but for a semi-active site you may
|
|
958
|
+
want to use a smaller value.
|
|
959
|
+
|
|
960
|
+
Also accepts a block which will be passed the job as soon as it
|
|
961
|
+
has completed processing. Useful for testing.</pre>
|
|
962
|
+
|
|
963
|
+
<p>OVERRIDE for multithreaded workers</p>
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
<div class="method-source-code" id="work-source">
|
|
968
|
+
<pre>
|
|
969
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 139</span>
|
|
970
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">work</span>(<span class="ruby-identifier">interval</span> = <span class="ruby-value">5</span>, &<span class="ruby-identifier">block</span>)
|
|
971
|
+
<span class="ruby-identifier">$0</span> = <span class="ruby-string">"resque: Starting"</span>
|
|
972
|
+
<span class="ruby-identifier">startup</span>
|
|
973
|
+
|
|
974
|
+
<span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
|
|
975
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@shutdown</span> <span class="ruby-operator">||</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:shutdown</span>]
|
|
976
|
+
|
|
977
|
+
<span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@paused</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">job</span> = <span class="ruby-identifier">reserve</span>
|
|
978
|
+
<span class="ruby-identifier">log</span> <span class="ruby-node">"got: #{job.inspect}"</span>
|
|
979
|
+
<span class="ruby-identifier">run_hook</span> <span class="ruby-value">:before_fork</span>
|
|
980
|
+
<span class="ruby-identifier">working_on</span> <span class="ruby-identifier">job</span>
|
|
981
|
+
|
|
982
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@child</span> = <span class="ruby-identifier">fork</span>
|
|
983
|
+
<span class="ruby-identifier">rand</span> <span class="ruby-comment"># Reseeding</span>
|
|
984
|
+
<span class="ruby-identifier">procline</span> <span class="ruby-node">"Forked #{@child} at #{Time.now.to_i}"</span>
|
|
985
|
+
<span class="ruby-constant">Process</span>.<span class="ruby-identifier">wait</span>
|
|
986
|
+
<span class="ruby-keyword">else</span>
|
|
987
|
+
<span class="ruby-identifier">procline</span> <span class="ruby-node">"Processing #{job.queue} since #{Time.now.to_i}"</span>
|
|
988
|
+
<span class="ruby-identifier">perform</span>(<span class="ruby-identifier">job</span>, &<span class="ruby-identifier">block</span>)
|
|
989
|
+
<span class="ruby-identifier">exit!</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@cant_fork</span>
|
|
990
|
+
<span class="ruby-keyword">end</span>
|
|
991
|
+
|
|
992
|
+
<span class="ruby-identifier">done_working</span>
|
|
993
|
+
<span class="ruby-ivar">@child</span> = <span class="ruby-keyword">nil</span>
|
|
994
|
+
<span class="ruby-keyword">else</span>
|
|
995
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">interval</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
|
996
|
+
<span class="ruby-identifier">log!</span> <span class="ruby-node">"Sleeping for #{interval.to_i}"</span>
|
|
997
|
+
<span class="ruby-identifier">procline</span> <span class="ruby-ivar">@paused</span> <span class="ruby-operator">?</span> <span class="ruby-string">"Paused"</span> <span class="ruby-operator">:</span> <span class="ruby-node">"Waiting for #{@queues.join(',')}"</span>
|
|
998
|
+
<span class="ruby-identifier">sleep</span> <span class="ruby-identifier">interval</span>.<span class="ruby-identifier">to_i</span>
|
|
999
|
+
<span class="ruby-keyword">end</span>
|
|
1000
|
+
<span class="ruby-keyword">end</span>
|
|
1001
|
+
<span class="ruby-identifier">unregister_worker</span> <span class="ruby-keyword">rescue</span> <span class="ruby-keyword">nil</span>
|
|
1002
|
+
<span class="ruby-identifier">loop</span> <span class="ruby-keyword">do</span>
|
|
1003
|
+
<span class="ruby-comment">#hang onto the process until all threads are done</span>
|
|
1004
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">all_workers_in_pid_working</span>.<span class="ruby-identifier">blank?</span>
|
|
1005
|
+
<span class="ruby-identifier">sleep</span> <span class="ruby-identifier">interval</span>.<span class="ruby-identifier">to_i</span>
|
|
1006
|
+
<span class="ruby-keyword">end</span>
|
|
1007
|
+
<span class="ruby-keyword">ensure</span>
|
|
1008
|
+
<span class="ruby-identifier">unregister_worker</span>
|
|
1009
|
+
<span class="ruby-keyword">end</span></pre>
|
|
1010
|
+
</div><!-- work-source -->
|
|
1011
|
+
|
|
1012
|
+
</div>
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
</div><!-- work-method -->
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
<div id="worker_pids-method" class="method-detail ">
|
|
1021
|
+
<a name="method-i-worker_pids"></a>
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
<div class="method-heading">
|
|
1025
|
+
<span class="method-name">worker_pids</span><span
|
|
1026
|
+
class="method-args">()</span>
|
|
1027
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
1028
|
+
</div>
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
<div class="method-description">
|
|
1032
|
+
|
|
1033
|
+
<p>Returns an array of string pids of all the other workers on this machine.
|
|
1034
|
+
Useful when pruning dead workers on startup.</p>
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
<div class="method-source-code" id="worker_pids-source">
|
|
1039
|
+
<pre>
|
|
1040
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 192</span>
|
|
1041
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">worker_pids</span>
|
|
1042
|
+
<span class="ruby-value">`ps -A -o pid,command | grep [r]esque`</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">"\n"</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
|
|
1043
|
+
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">' '</span>)[<span class="ruby-value">0</span>]
|
|
1044
|
+
<span class="ruby-keyword">end</span>
|
|
1045
|
+
<span class="ruby-keyword">end</span></pre>
|
|
1046
|
+
</div><!-- worker_pids-source -->
|
|
1047
|
+
|
|
1048
|
+
</div>
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
</div><!-- worker_pids-method -->
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
<div id="workers_in_pid-method" class="method-detail ">
|
|
1057
|
+
<a name="method-i-workers_in_pid"></a>
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
<div class="method-heading">
|
|
1061
|
+
<span class="method-name">workers_in_pid</span><span
|
|
1062
|
+
class="method-args">()</span>
|
|
1063
|
+
<span class="method-click-advice">click to toggle source</span>
|
|
1064
|
+
</div>
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
<div class="method-description">
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
<div class="method-source-code" id="workers_in_pid-source">
|
|
1074
|
+
<pre>
|
|
1075
|
+
<span class="ruby-comment"># File lib/resque_ui/overrides/resque/worker.rb, line 37</span>
|
|
1076
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">workers_in_pid</span>
|
|
1077
|
+
<span class="ruby-constant">Array</span>(<span class="ruby-identifier">redis</span>.<span class="ruby-identifier">smembers</span>(<span class="ruby-value">:workers</span>)).<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">id</span><span class="ruby-operator">|</span> <span class="ruby-identifier">id</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/\(#{ip}\):#{pid}/</span> }.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">id</span><span class="ruby-operator">|</span> <span class="ruby-constant">Resque</span><span class="ruby-operator">::</span><span class="ruby-constant">Worker</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>) }.<span class="ruby-identifier">compact</span>
|
|
1078
|
+
<span class="ruby-keyword">end</span></pre>
|
|
1079
|
+
</div><!-- workers_in_pid-source -->
|
|
1080
|
+
|
|
1081
|
+
</div>
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
</div><!-- workers_in_pid-method -->
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
</div><!-- public-instance-method-details -->
|
|
1090
|
+
|
|
1091
|
+
</div><!-- 5Buntitled-5D -->
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
</div><!-- documentation -->
|
|
1095
|
+
|
|
1096
|
+
<div id="validator-badges">
|
|
1097
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
1098
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
|
1099
|
+
Rdoc Generator</a> 2</small>.</p>
|
|
1100
|
+
</div>
|
|
1101
|
+
|
|
1102
|
+
</body>
|
|
1103
|
+
</html>
|
|
1104
|
+
|