|
@@ -60,6 +60,13 @@ class GearmanExecute extends AbstractGearmanService
|
|
*/
|
|
*/
|
|
protected $executeOptionsResolver;
|
|
protected $executeOptionsResolver;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Boolean to track if a system signal has been received
|
|
|
|
+ * @var boolean
|
|
|
|
+ */
|
|
|
|
+ protected $stopWorkSignalReceived;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Construct method
|
|
* Construct method
|
|
*
|
|
*
|
|
@@ -83,6 +90,28 @@ class GearmanExecute extends AbstractGearmanService
|
|
'timeout' => array('null', 'scalar'),
|
|
'timeout' => array('null', 'scalar'),
|
|
))
|
|
))
|
|
;
|
|
;
|
|
|
|
+
|
|
|
|
+ $this->stopWorkSignalReceived = false;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * If the pcntl_signal exists, subscribe to the terminate and restart events for graceful worker stops.
|
|
|
|
+ */
|
|
|
|
+ if(false !== function_exists('pcntl_signal'))
|
|
|
|
+ {
|
|
|
|
+ declare(ticks = 1);
|
|
|
|
+ pcntl_signal(SIGTERM, array($this,"handleSystemSignal"));
|
|
|
|
+ pcntl_signal(SIGHUP, array($this,"handleSystemSignal"));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Toggles that work should be stopped, we only subscribe to SIGTERM and SIGHUP
|
|
|
|
+ * @param int $signno Signal number
|
|
|
|
+ */
|
|
|
|
+ public function handleSystemSignal($signo)
|
|
|
|
+ {
|
|
|
|
+ $this->stopWorkSignalReceived = true;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -299,7 +328,7 @@ class GearmanExecute extends AbstractGearmanService
|
|
/**
|
|
/**
|
|
* Executes GearmanWorker with all jobs defined
|
|
* Executes GearmanWorker with all jobs defined
|
|
*/
|
|
*/
|
|
- while ($gearmanWorker->work()) {
|
|
|
|
|
|
+ while (false === $this->stopWorkSignalReceived && $gearmanWorker->work()) {
|
|
|
|
|
|
$iterations--;
|
|
$iterations--;
|
|
|
|
|