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

Add a progress bar to the queue:run command #5986

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Commands/core/QueueCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,18 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items-
$queue->garbageCollection();
}

$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 {
$this->logger()->info(dt('Processing item @id from @name queue.', ['@name' => $name, '@id' => $item->item_id ?? $item->qid]));
$worker->processItem($item->data);
$queue->deleteItem($item);
$count++;
$this->io()->progressAdvance();
} catch (RequeueException $e) {
// The worker requested the task to be immediately requeued.
$queue->releaseItem($item);
Expand Down Expand Up @@ -131,6 +137,9 @@ public function run(string $name, $options = ['time-limit' => self::REQ, 'items-
$remaining = $end - time();
}
$elapsed = microtime(true) - $start;
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)]));
}

Expand Down