diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 28cb368fb0d8..0c1c6e176c03 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -39,6 +39,13 @@ class Worker */ protected $exceptions; + /** + * Indicates if the worker should exit. + * + * @var bool + */ + protected $shouldQuit = false; + /** * Indicates if the worker is paused. * @@ -87,6 +94,10 @@ public function daemon($connectionName, $queue, WorkerOptions $options) $this->registerTimeoutHandler($job, $options); + if ($this->shouldQuit) { + $this->kill(); + } + // If the daemon should run (not in maintenance mode, etc.), then we can run // fire off this job for processing. Otherwise, we will need to sleep the // worker so no more jobs are processed until they should be processed. @@ -448,6 +459,10 @@ protected function listenForSignals() if ($this->supportsAsyncSignals()) { pcntl_async_signals(true); + pcntl_signal(SIGQUIT, function () { + $this->shouldQuit = true; + }); + pcntl_signal(SIGUSR2, function () { $this->paused = true; });