Skip to content

Commit 00a12e2

Browse files
PHPGuustaylorotwell
authored andcommitted
Add --rest option to queue:listen
+ `sleep()` if there was a rest option + Add `rest` to the `ListenerOptions` + Add `--rest` to the `ListenCommand` and store the value in the `ListenerOptions`
1 parent 695e8f0 commit 00a12e2

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/Illuminate/Queue/Console/ListenCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class ListenCommand extends Command
2525
{--queue= : The queue to listen on}
2626
{--sleep=3 : Number of seconds to sleep when no job is available}
2727
{--timeout=60 : The number of seconds a child process can run}
28-
{--tries=1 : Number of times to attempt a job before logging it failed}';
28+
{--tries=1 : Number of times to attempt a job before logging it failed}
29+
{--rest=0 : Number of seconds to rest between jobs}';
2930

3031
/**
3132
* The name of the console command.
@@ -120,7 +121,8 @@ protected function gatherOptions()
120121
$this->option('timeout'),
121122
$this->option('sleep'),
122123
$this->option('tries'),
123-
$this->option('force')
124+
$this->option('force'),
125+
$this->option('rest')
124126
);
125127
}
126128

src/Illuminate/Queue/Listener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public function listen($connection, $queue, ListenerOptions $options)
8888

8989
while (true) {
9090
$this->runProcess($process, $options->memory);
91+
if($options->rest) {
92+
sleep($options->rest);
93+
}
9194
}
9295
}
9396

src/Illuminate/Queue/ListenerOptions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ class ListenerOptions extends WorkerOptions
2222
* @param int $sleep
2323
* @param int $maxTries
2424
* @param bool $force
25+
* @param int $rest
2526
* @return void
2627
*/
27-
public function __construct($name = 'default', $environment = null, $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false)
28+
public function __construct($name = 'default', $environment = null, $backoff = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false, $rest = 0)
2829
{
2930
$this->environment = $environment;
3031

31-
parent::__construct($name, $backoff, $memory, $timeout, $sleep, $maxTries, $force);
32+
parent::__construct($name, $backoff, $memory, $timeout, $sleep, $maxTries, $force, false, 0, 0, $rest);
3233
}
3334
}

0 commit comments

Comments
 (0)