Skip to content

Commit

Permalink
Gracefully handle SIGQUIT.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 30, 2017
1 parent d939078 commit b38ba01
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
});
Expand Down

0 comments on commit b38ba01

Please sign in to comment.