Skip to content

Commit

Permalink
Do not run queue workers while application is in maintenance mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 31, 2013
1 parent aa6df0a commit a8cdb68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/changes.json
Expand Up @@ -62,6 +62,7 @@
{"message": "Added Cookie::queue method for creating cookies that are automatically attached to the final response.", "backport": null}, {"message": "Added Cookie::queue method for creating cookies that are automatically attached to the final response.", "backport": null},
{"message": "Allow environment to be checked via App::environment method.", "backport": null}, {"message": "Allow environment to be checked via App::environment method.", "backport": null},
{"message": "Add support for order by and limit on MySQL update queries.", "backport": null}, {"message": "Add support for order by and limit on MySQL update queries.", "backport": null},
{"message": "Tweak Container::resolve to accept a type, new resolvingAny method for all objects.", "backport": null} {"message": "Tweak Container::resolve to accept a type, new resolvingAny method for all objects.", "backport": null},
{"message": "Do not run queue workers while application is in maintenance mode.", "backport": null}
] ]
} }
16 changes: 16 additions & 0 deletions src/Illuminate/Queue/Console/WorkCommand.php
Expand Up @@ -48,6 +48,8 @@ public function __construct(Worker $worker)
*/ */
public function fire() public function fire()
{ {
if ($this->downForMaintenance()) return;

$queue = $this->option('queue'); $queue = $this->option('queue');


$delay = $this->option('delay'); $delay = $this->option('delay');
Expand All @@ -62,6 +64,18 @@ public function fire()
$this->worker->pop($connection, $queue, $delay, $memory, $this->option('sleep')); $this->worker->pop($connection, $queue, $delay, $memory, $this->option('sleep'));
} }


/**
* Determine if the worker should run in maintenance mode.
*
* @return bool
*/
protected function downForMaintenance()
{
if ($this->option('force')) return false;

return $this->laravel->isDownForMaintenance();
}

/** /**
* Get the console command arguments. * Get the console command arguments.
* *
Expand All @@ -86,6 +100,8 @@ protected function getOptions()


array('delay', null, InputOption::VALUE_OPTIONAL, 'Amount of time to delay failed jobs', 0), array('delay', null, InputOption::VALUE_OPTIONAL, 'Amount of time to delay failed jobs', 0),


array('force', null, InputOption::VALUE_NONE, 'Force the worker to run even in maintenance mode.'),

array('memory', null, InputOption::VALUE_OPTIONAL, 'The memory limit in megabytes', 128), array('memory', null, InputOption::VALUE_OPTIONAL, 'The memory limit in megabytes', 128),


array('sleep', null, InputOption::VALUE_OPTIONAL, 'Number of seconds to sleep when no job is available', 3), array('sleep', null, InputOption::VALUE_OPTIONAL, 'Number of seconds to sleep when no job is available', 3),
Expand Down

0 comments on commit a8cdb68

Please sign in to comment.