Skip to content

Commit 72c50d3

Browse files
committed
Add pause/ resume handling to ScheduleWorker.
This is a copy from ResqueWorker.
1 parent 2ca68e9 commit 72c50d3

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/ResqueScheduler/Worker.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class ResqueScheduler_Worker
3030
*/
3131
private $shutdown = false;
3232

33+
/**
34+
* @var boolean True if this worker is paused.
35+
*/
36+
private $paused = false;
37+
3338
/**
3439
* The primary loop for a worker.
3540
*
@@ -51,7 +56,9 @@ public function work($interval = null)
5156
if($this->shutdown) {
5257
break;
5358
}
54-
$this->handleDelayedItems();
59+
if(!$this->paused) {
60+
$this->handleDelayedItems();
61+
}
5562
$this->sleep();
5663
}
5764
}
@@ -152,10 +159,33 @@ private function registerSigHandlers()
152159
pcntl_signal(SIGTERM, array($this, 'shutdown'));
153160
pcntl_signal(SIGINT, array($this, 'shutdown'));
154161
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');
155166
}
156167

157168
public function shutdown()
158169
{
170+
$this->log('Shutting down');
159171
$this->shutdown = true;
160172
}
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+
}
161191
}

0 commit comments

Comments
 (0)