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

[10.x] Display queue runtime in human readable format #47227

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -216,7 +217,7 @@ protected function writeOutput(Job $job, $status)
return $this->output->writeln(' <fg=yellow;options=bold>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
Expand Down Expand Up @@ -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.
*
Expand Down