From 2fb57a1ba13fffb96ce01cd11d4662890427f721 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Mon, 18 May 2026 21:37:46 +0800 Subject: [PATCH 1/2] fix: fix output timestamp in WorkCommand while in coroutines --- src/queue/src/Console/WorkCommand.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/queue/src/Console/WorkCommand.php b/src/queue/src/Console/WorkCommand.php index 041a6aea8..8ff9b2375 100644 --- a/src/queue/src/Console/WorkCommand.php +++ b/src/queue/src/Console/WorkCommand.php @@ -6,6 +6,7 @@ use Hypervel\Config\Repository; use Hypervel\Console\Command; +use Hypervel\Context\Context; use Hypervel\Contracts\Cache\Factory as CacheFactory; use Hypervel\Contracts\Container\Container; use Hypervel\Contracts\Queue\Job; @@ -59,11 +60,6 @@ class WorkCommand extends Command */ protected string $description = 'Start processing jobs on the queue as a daemon'; - /** - * Holds the start time of the last processed job, if any. - */ - protected ?float $latestStartedAt = null; - /** * Indicates if the worker's event listeners have been registered. */ @@ -218,7 +214,7 @@ protected function writeOutputForCli(Job $job, string $status): void )); if ($status == 'starting') { - $this->latestStartedAt = microtime(true); + $this->setLatestStartedAt(microtime(true)); $dots = max(terminal()->width() - mb_strlen($job->resolveName()) - ( $this->output->isVerbose() ? (mb_strlen($job->getJobId()) + 1) : 0 @@ -231,7 +227,7 @@ protected function writeOutputForCli(Job $job, string $status): void return; } - $runTime = $this->runTimeForHumans($this->latestStartedAt); + $runTime = $this->runTimeForHumans($this->getLatestStartedAt()); $dots = max(terminal()->width() - mb_strlen($job->resolveName()) - ( $this->output->isVerbose() ? (mb_strlen($job->getJobId()) + 1) : 0 @@ -274,9 +270,9 @@ protected function writeOutputAsJson(Job $job, $status, ?Throwable $exception = ]); if ($status === 'starting') { - $this->latestStartedAt = microtime(true); + $this->setLatestStartedAt(microtime(true)); } else { - $log['duration'] = round(microtime(true) - $this->latestStartedAt, 6); + $log['duration'] = round(microtime(true) - $this->getLatestStartedAt(), 6); } $this->output->writeln(json_encode($log)); @@ -350,4 +346,14 @@ public static function flushState(): void { static::$hasRegisteredListeners = false; } + + protected function getLatestStartedAt(): ?float + { + return Context::get('__queue.worker.latest_started_at'); + } + + protected function setLatestStartedAt(?float $latestStartedAt): void + { + Context::set('__queue.worker.latest_started_at', $latestStartedAt); + } } From 8fab43c96f9f63ebc62b4966bccb310ed88c4047 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Mon, 18 May 2026 21:50:10 +0800 Subject: [PATCH 2/2] fix: use coroutine context instead --- src/queue/src/Console/WorkCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/queue/src/Console/WorkCommand.php b/src/queue/src/Console/WorkCommand.php index 8ff9b2375..f27c2bb82 100644 --- a/src/queue/src/Console/WorkCommand.php +++ b/src/queue/src/Console/WorkCommand.php @@ -6,7 +6,7 @@ use Hypervel\Config\Repository; use Hypervel\Console\Command; -use Hypervel\Context\Context; +use Hypervel\Context\CoroutineContext; use Hypervel\Contracts\Cache\Factory as CacheFactory; use Hypervel\Contracts\Container\Container; use Hypervel\Contracts\Queue\Job; @@ -349,11 +349,11 @@ public static function flushState(): void protected function getLatestStartedAt(): ?float { - return Context::get('__queue.worker.latest_started_at'); + return CoroutineContext::get('__queue.worker.latest_started_at'); } protected function setLatestStartedAt(?float $latestStartedAt): void { - Context::set('__queue.worker.latest_started_at', $latestStartedAt); + CoroutineContext::set('__queue.worker.latest_started_at', $latestStartedAt); } }