Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Fix queue:work --force option in maintenance mode #16468

Merged
merged 1 commit into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}