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

[8.x] Ability to slow the workers down #36521

Merged
merged 1 commit into from
Mar 9, 2021
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
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
2 changes: 2 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
$jobsProcessed++;

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

$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 @@ -74,6 +74,13 @@ class WorkerOptions
*/
public $maxTime;

/**
* The number of seconds to rest between jobs.
*
* @var int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your example is float?

Copy link
Member Author

@themsaid themsaid Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to sleep. maybe in another commit we change both to float|int.

*/
public $rest;

/**
* Create a new worker options instance.
*
Expand All @@ -87,10 +94,11 @@ 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;
Expand All @@ -102,5 +110,6 @@ public function __construct($name = 'default', $backoff = 0, $memory = 128, $tim
$this->stopWhenEmpty = $stopWhenEmpty;
$this->maxJobs = $maxJobs;
$this->maxTime = $maxTime;
$this->rest = $rest;
}
}