From a81a1c2c7be1cc58381250fcb8c7f57c5cabebf1 Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Fri, 2 Aug 2024 18:13:06 +0200 Subject: [PATCH 1/3] Add progress bar to queue:run command --- src/Commands/core/QueueCommands.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Commands/core/QueueCommands.php b/src/Commands/core/QueueCommands.php index 6e0c755619..b2982cac9e 100644 --- a/src/Commands/core/QueueCommands.php +++ b/src/Commands/core/QueueCommands.php @@ -74,6 +74,8 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items- $queue->garbageCollection(); } + $this->io()->progressStart($items_limit ?: $queue->numberOfItems()); + while ((!$time_limit || $remaining > 0) && (!$items_limit || $count < $items_limit) && ($item = $queue->claimItem($lease_time))) { try { // @phpstan-ignore-next-line @@ -82,6 +84,7 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items- $worker->processItem($item->data); $queue->deleteItem($item); $count++; + $this->io()->progressAdvance(); } catch (RequeueException) { // The worker requested the task to be immediately requeued. $queue->releaseItem($item); From 9ac342c41f5f76c6cd8e0d5283c1c2210ad0b02b Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Mon, 6 May 2024 20:32:23 +0200 Subject: [PATCH 2/3] Finish the progress bar --- src/Commands/core/QueueCommands.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/core/QueueCommands.php b/src/Commands/core/QueueCommands.php index b2982cac9e..f99383f1e4 100644 --- a/src/Commands/core/QueueCommands.php +++ b/src/Commands/core/QueueCommands.php @@ -112,6 +112,7 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items- $remaining = $end - time(); } $elapsed = microtime(true) - $start; + $this->io()->progressFinish(); $this->logger()->success(dt('Processed @count items from the @name queue in @elapsed sec.', ['@count' => $count, '@name' => $name, '@elapsed' => round($elapsed, 2)])); } From 06e36ddf886907b4f818cd2f05c95cb75eb561cf Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Mon, 6 May 2024 21:59:36 +0200 Subject: [PATCH 3/3] Only start progress bar if any queue items --- src/Commands/core/QueueCommands.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Commands/core/QueueCommands.php b/src/Commands/core/QueueCommands.php index f99383f1e4..e181574378 100644 --- a/src/Commands/core/QueueCommands.php +++ b/src/Commands/core/QueueCommands.php @@ -74,7 +74,10 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items- $queue->garbageCollection(); } - $this->io()->progressStart($items_limit ?: $queue->numberOfItems()); + $max = $items_limit ?: $queue->numberOfItems(); + if ($max > 0) { + $this->io()->progressStart($max); + } while ((!$time_limit || $remaining > 0) && (!$items_limit || $count < $items_limit) && ($item = $queue->claimItem($lease_time))) { try { @@ -112,7 +115,9 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items- $remaining = $end - time(); } $elapsed = microtime(true) - $start; - $this->io()->progressFinish(); + if ($max > 0) { + $this->io()->progressFinish(); + } $this->logger()->success(dt('Processed @count items from the @name queue in @elapsed sec.', ['@count' => $count, '@name' => $name, '@elapsed' => round($elapsed, 2)])); }