Skip to content

Commit

Permalink
[5.3] Fix queue:work --force option in maintenance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shadoWalker89 committed Nov 18, 2016
1 parent 58be0ca commit 7149a96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function gatherWorkerOptions()
return new WorkerOptions(
$this->option('delay'), $this->option('memory'),
$this->option('timeout'), $this->option('sleep'),
$this->option('tries')
$this->option('tries'), $this->option('force')
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
while (true) {
$this->registerTimeoutHandler($options);

if ($this->daemonShouldRun()) {
if ($this->daemonShouldRun($options)) {
$this->runNextJob($connectionName, $queue, $options);
} else {
$this->sleep($options->sleep);
Expand Down Expand Up @@ -110,11 +110,12 @@ protected function registerTimeoutHandler(WorkerOptions $options)
/**
* Determine if the daemon should process on this iteration.
*
* @param WorkerOptions $options
* @return bool
*/
protected function daemonShouldRun()
protected function daemonShouldRun(WorkerOptions $options)
{
if ($this->manager->isDownForMaintenance() ||
if (($this->manager->isDownForMaintenance() && ! $options->force) ||
$this->events->until('illuminate.queue.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
11 changes: 10 additions & 1 deletion src/Illuminate/Queue/WorkerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class WorkerOptions
*/
public $maxTries;

/**
* Determine if the worker should run in maintenance mode.
*
* @var bool
*/
public $force;

/**
* Create a new worker options instance.
*
Expand All @@ -47,13 +54,15 @@ class WorkerOptions
* @param int $timeout
* @param int $sleep
* @param int $maxTries
* @param bool $force
*/
public function __construct($delay = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 0)
public function __construct($delay = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 0, $force = false)
{
$this->delay = $delay;
$this->sleep = $sleep;
$this->memory = $memory;
$this->timeout = $timeout;
$this->maxTries = $maxTries;
$this->force = $force;
}
}

0 comments on commit 7149a96

Please sign in to comment.