Skip to content

Commit

Permalink
convert milliseconds to human readable timestamps using Carbon
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldyrynda committed May 26, 2023
1 parent 4e8e644 commit b1a3f48
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 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->resolveRunTime();

$dots = max(terminal()->width() - mb_strlen($job->resolveName()) - (
$this->output->isVerbose() ? (mb_strlen($job->getJobId()) + 1) : 0
Expand Down Expand Up @@ -287,4 +288,20 @@ protected function downForMaintenance()
{
return $this->option('force') ? false : $this->laravel->isDownForMaintenance();
}

/**
* Format the worked runtime for human readability.
*
* @return string
*/
protected function resolveRunTime()
{
$runTime = number_format((microtime(true) - $this->latestStartedAt) * 1000, 2);

if ($runTime > 1) {
return CarbonInterval::milliseconds($runTime)->cascade()->forHumans(short: true);
}

return $runTime.'ms';
}
}

0 comments on commit b1a3f48

Please sign in to comment.