Skip to content

Commit

Permalink
support pause and continue signals
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 13, 2017
1 parent fec5da0 commit 827d075
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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 is paused.
*
* @var bool
*/
protected $paused = false;

/**
* Create a new queue worker.
*
Expand Down Expand Up @@ -143,6 +150,7 @@ protected function timeoutForJob($job, WorkerOptions $options)
protected function daemonShouldRun(WorkerOptions $options)
{
if (($this->manager->isDownForMaintenance() && ! $options->force) ||
$this->paused ||
$this->events->until(new Events\Looping) === false) {
// If the application is down for maintenance or doesn't want the queues to run
// we will sleep for one second just in case the developer has it set to not
Expand Down Expand Up @@ -439,6 +447,14 @@ protected function listenForSignals()
{
if ($this->supportsAsyncSignals()) {
pcntl_async_signals(true);

pcntl_signal(SIGUSR2, function () {
$this->paused = true;
});

pcntl_signal(SIGCONT, function () {
$this->paused = false;
});
}
}

Expand Down

0 comments on commit 827d075

Please sign in to comment.