diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index 2cf44161b8d5..b4ed14443f62 100644 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -2,6 +2,7 @@ namespace Illuminate\Queue\Console; +use Carbon\CarbonInterval; use Illuminate\Console\Command; use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Contracts\Queue\Job; @@ -216,7 +217,7 @@ protected function writeOutput(Job $job, $status) return $this->output->writeln(' RUNNING'); } - $runTime = number_format((microtime(true) - $this->latestStartedAt) * 1000, 2).'ms'; + $runTime = $this->formatRunTime($this->latestStartedAt); $dots = max(terminal()->width() - mb_strlen($job->resolveName()) - ( $this->output->isVerbose() ? (mb_strlen($job->getJobId()) + 1) : 0 @@ -249,6 +250,21 @@ protected function now() return Carbon::now(); } + /** + * Given a start time, format the total run time for human readability. + * + * @param float $startTime + * @return string + */ + protected function formatRunTime($startTime) + { + $runTime = (microtime(true) - $startTime) * 1000; + + return $runTime > 1000 + ? CarbonInterval::milliseconds($runTime)->cascade()->forHumans(short: true) + : number_format($runTime, 2).'ms'; + } + /** * Store a failed job event. *