Skip to content

Commit

Permalink
Add --rest option to queue:listen
Browse files Browse the repository at this point in the history
+ `sleep()` if there was a rest option
+ Add `rest` to the `ListenerOptions`
+ Add `--rest` to the `ListenCommand` and store the value in
  the `ListenerOptions`
  • Loading branch information
PHPGuus authored and taylorotwell committed Nov 25, 2022
1 parent 695e8f0 commit 00a12e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Illuminate/Queue/Console/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class ListenCommand extends Command
{--queue= : The queue to listen on}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--timeout=60 : The number of seconds a child process can run}
{--tries=1 : Number of times to attempt a job before logging it failed}';
{--tries=1 : Number of times to attempt a job before logging it failed}
{--rest=0 : Number of seconds to rest between jobs}';

/**
* The name of the console command.
Expand Down Expand Up @@ -120,7 +121,8 @@ protected function gatherOptions()
$this->option('timeout'),
$this->option('sleep'),
$this->option('tries'),
$this->option('force')
$this->option('force'),
$this->option('rest')
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Queue/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public function listen($connection, $queue, ListenerOptions $options)

while (true) {
$this->runProcess($process, $options->memory);
if($options->rest) {
sleep($options->rest);
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Queue/ListenerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class ListenerOptions extends WorkerOptions
* @param int $sleep
* @param int $maxTries
* @param bool $force
* @param int $rest
* @return void
*/
public function __construct($name = 'default', $environment = null, $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false)
public function __construct($name = 'default', $environment = null, $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false, $rest = 0)
{
$this->environment = $environment;

parent::__construct($name, $backoff, $memory, $timeout, $sleep, $maxTries, $force);
parent::__construct($name, $backoff, $memory, $timeout, $sleep, $maxTries, $force, false, 0, 0, $rest);
}
}

0 comments on commit 00a12e2

Please sign in to comment.