Skip to content

Commit bbdc8f2

Browse files
authored
Merge pull request #23 from techmahedy/techmahedy-1.x
default queue worker timeout 3600 seconds to unlimited
2 parents 0380fa6 + f30bc14 commit bbdc8f2

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/Commands/QueueRunCommand.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class QueueRunCommand extends Command
1313
*
1414
* @var string
1515
*/
16-
protected $name = 'queue:run {--queue=default} {--sleep=3} {--memory=128} {--timeout=3600} {--limit=}';
16+
protected $name = 'queue:run {--queue=default} {--sleep=3} {--memory=128} {--timeout=0} {--limit=}';
1717

1818
/**
1919
* The command description.
@@ -50,7 +50,7 @@ public function __construct(QueueManager $manager)
5050

5151
/**
5252
* Execute the console command.
53-
* Example: php pool queue:run --queue=reports --sleep=10 --memory=1024 --timeout=3600 --limit=
53+
* Example: php pool queue:run --queue=reports --sleep=10 --memory=1024 --timeout=0 --limit=
5454
*
5555
* @return int
5656
*/
@@ -60,13 +60,21 @@ protected function handle(): int
6060
$queue = $this->option('queue', 'default');
6161
$sleep = (int) $this->option('sleep', 3);
6262
$maxMemory = (int) $this->option('memory', 128);
63-
$maxTime = (int) $this->option('timeout', 3600);
64-
$maxLimit = $this->option('limit');
6563

64+
$maxTimeInput = $this->option('timeout');
65+
$maxTime = $maxTimeInput !== 0 ? (int) $maxTimeInput : -1;
66+
67+
$maxLimit = $this->option('limit');
6668
$maxLimit = $maxLimit !== null ? (int) $maxLimit : null;
6769

6870
$this->displaySuccess("Starting queue worker on queue: {$queue}");
69-
$configInfo = "Configuration: sleep={$sleep}s, memory={$maxMemory}MB, timeout={$maxTime}s";
71+
$configInfo = "Configuration: sleep={$sleep}s, memory={$maxMemory}MB, timeout=";
72+
73+
if ($maxTime > 0) {
74+
$configInfo .= "{$maxTime}s";
75+
} else {
76+
$configInfo .= "unlimited";
77+
}
7078

7179
if (!empty($maxLimit)) {
7280
$configInfo .= ", limit={$maxLimit} jobs";

src/QueueWorker.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QueueWorker
2727
*
2828
* @var int
2929
*/
30-
protected $maxExecutionTime = 3600;
30+
protected $maxExecutionTime = 0;
3131

3232
/**
3333
* The number of seconds to wait before polling the queue.
@@ -453,6 +453,10 @@ protected function memoryExceeded(): bool
453453
*/
454454
protected function timeExceeded(int $startTime): bool
455455
{
456+
if ($this->maxExecutionTime <= 0) {
457+
return false;
458+
}
459+
456460
return (time() - $startTime) >= $this->maxExecutionTime;
457461
}
458462

0 commit comments

Comments
 (0)