Skip to content

Commit

Permalink
Merge branch 'pr9285' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 9, 2021
2 parents 37e48ba + c6ea49c commit e2e98f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WorkCommand extends Command
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--rest=0 : Number of seconds to rest between jobs}
{--timeout=60 : The number of seconds a child process can run}
{--tries=1 : Number of times to attempt a job before logging it failed}';

Expand Down Expand Up @@ -134,7 +135,8 @@ protected function gatherWorkerOptions()
$this->option('force'),
$this->option('stop-when-empty'),
$this->option('max-jobs'),
$this->option('max-time')
$this->option('max-time'),
$this->option('rest')
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
$jobsProcessed++;

$this->runJob($job, $connectionName, $options);

if ($options->rest > 0) {
$this->sleep($options->rest);
}
} else {
$this->sleep($options->sleep);
}
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 $sleep;

/**
* The number of seconds to rest between jobs.
*
* @var int
*/
public $rest;

/**
* The maximum amount of times a job may be attempted.
*
Expand Down Expand Up @@ -87,14 +94,16 @@ class WorkerOptions
* @param bool $stopWhenEmpty
* @param int $maxJobs
* @param int $maxTime
* @param int $rest
* @return void
*/
public function __construct($name = 'default', $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1,
$force = false, $stopWhenEmpty = false, $maxJobs = 0, $maxTime = 0)
$force = false, $stopWhenEmpty = false, $maxJobs = 0, $maxTime = 0, $rest = 0)
{
$this->name = $name;
$this->backoff = $backoff;
$this->sleep = $sleep;
$this->rest = $rest;
$this->force = $force;
$this->memory = $memory;
$this->timeout = $timeout;
Expand Down

0 comments on commit e2e98f4

Please sign in to comment.