@@ -30,6 +30,11 @@ class ResqueScheduler_Worker
30
30
*/
31
31
private $ shutdown = false ;
32
32
33
+ /**
34
+ * @var boolean True if this worker is paused.
35
+ */
36
+ private $ paused = false ;
37
+
33
38
/**
34
39
* The primary loop for a worker.
35
40
*
@@ -51,7 +56,9 @@ public function work($interval = null)
51
56
if ($ this ->shutdown ) {
52
57
break ;
53
58
}
54
- $ this ->handleDelayedItems ();
59
+ if (!$ this ->paused ) {
60
+ $ this ->handleDelayedItems ();
61
+ }
55
62
$ this ->sleep ();
56
63
}
57
64
}
@@ -152,10 +159,33 @@ private function registerSigHandlers()
152
159
pcntl_signal (SIGTERM , array ($ this , 'shutdown ' ));
153
160
pcntl_signal (SIGINT , array ($ this , 'shutdown ' ));
154
161
pcntl_signal (SIGQUIT , array ($ this , 'shutdown ' ));
162
+ pcntl_signal (SIGUSR2 , array ($ this , 'pauseProcessing ' ));
163
+ pcntl_signal (SIGCONT , array ($ this , 'unPauseProcessing ' ));
164
+
165
+ $ this ->log ('Registered signals ' );
155
166
}
156
167
157
168
public function shutdown ()
158
169
{
170
+ $ this ->log ('Shutting down ' );
159
171
$ this ->shutdown = true ;
160
172
}
173
+
174
+ /**
175
+ * Signal handler callback for USR2, pauses processing.
176
+ */
177
+ public function pauseProcessing ()
178
+ {
179
+ $ this ->log ('USR2 received; pausing processing ' );
180
+ $ this ->paused = true ;
181
+ }
182
+
183
+ /**
184
+ * Signal handler callback for CONT, resume processing.
185
+ */
186
+ public function unPauseProcessing ()
187
+ {
188
+ $ this ->log ('CONT received; resuming processing ' );
189
+ $ this ->paused = false ;
190
+ }
161
191
}
0 commit comments