|
13 | 13 | use Illuminate\Queue\WorkerOptions;
|
14 | 14 | use Illuminate\Support\Carbon;
|
15 | 15 | use Symfony\Component\Console\Attribute\AsCommand;
|
| 16 | +use Symfony\Component\Console\Terminal; |
16 | 17 | use function Termwind\terminal;
|
17 | 18 |
|
18 | 19 | #[AsCommand(name: 'queue:work')]
|
@@ -80,13 +81,6 @@ class WorkCommand extends Command
|
80 | 81 | */
|
81 | 82 | protected $latestStartedAt;
|
82 | 83 |
|
83 |
| - /** |
84 |
| - * Holds the status of the last processed job, if any. |
85 |
| - * |
86 |
| - * @var string|null |
87 |
| - */ |
88 |
| - protected $latestStatus; |
89 |
| - |
90 | 84 | /**
|
91 | 85 | * Create a new queue work command.
|
92 | 86 | *
|
@@ -126,9 +120,11 @@ public function handle()
|
126 | 120 | // connection being run for the queue operation currently being executed.
|
127 | 121 | $queue = $this->getQueue($connection);
|
128 | 122 |
|
129 |
| - $this->components->info( |
130 |
| - sprintf('Processing jobs from the [%s] %s.', $queue, str('queue')->plural(explode(',', $queue))) |
131 |
| - ); |
| 123 | + if (Terminal::hasSttyAvailable()) { |
| 124 | + $this->components->info( |
| 125 | + sprintf('Processing jobs from the [%s] %s.', $queue, str('queue')->plural(explode(',', $queue))) |
| 126 | + ); |
| 127 | + } |
132 | 128 |
|
133 | 129 | return $this->runWorker(
|
134 | 130 | $connection, $queue
|
@@ -208,28 +204,37 @@ protected function listenForEvents()
|
208 | 204 | */
|
209 | 205 | protected function writeOutput(Job $job, $status)
|
210 | 206 | {
|
| 207 | + $this->output->write(sprintf( |
| 208 | + ' <fg=gray>%s</> %s%s', |
| 209 | + Carbon::now()->format('Y-m-d H:i:s'), |
| 210 | + $job->resolveName(), |
| 211 | + $this->output->isVerbose() |
| 212 | + ? sprintf(' <fg=gray>%s</>', $job->getJobId()) |
| 213 | + : '' |
| 214 | + )); |
| 215 | + |
211 | 216 | if ($status == 'starting') {
|
212 | 217 | $this->latestStartedAt = microtime(true);
|
213 |
| - $this->latestStatus = $status; |
214 | 218 |
|
215 |
| - $formattedStartedAt = Carbon::now()->format('Y-m-d H:i:s'); |
| 219 | + $dots = max(terminal()->width() - mb_strlen($job->resolveName()) - ( |
| 220 | + $this->output->isVerbose() ? (mb_strlen($job->getJobId()) + 1) : 0 |
| 221 | + ) - 33, 0); |
216 | 222 |
|
217 |
| - return $this->output->write(" <fg=gray>{$formattedStartedAt}</> {$job->resolveName()}"); |
218 |
| - } |
| 223 | + $this->output->write(' '.str_repeat('<fg=gray>.</>', $dots)); |
219 | 224 |
|
220 |
| - if ($this->latestStatus && $this->latestStatus != 'starting') { |
221 |
| - $formattedStartedAt = Carbon::createFromTimestamp($this->latestStartedAt)->format('Y-m-d H:i:s'); |
222 |
| - |
223 |
| - $this->output->write(" <fg=gray>{$formattedStartedAt}</> {$job->resolveName()}"); |
| 225 | + return $this->output->writeln(' <fg=yellow;options=bold>RUNNING</>'); |
224 | 226 | }
|
225 | 227 |
|
226 | 228 | $runTime = number_format((microtime(true) - $this->latestStartedAt) * 1000, 2).'ms';
|
227 |
| - $dots = max(terminal()->width() - mb_strlen($job->resolveName()) - mb_strlen($runTime) - 31, 0); |
| 229 | + |
| 230 | + $dots = max(terminal()->width() - mb_strlen($job->resolveName()) - ( |
| 231 | + $this->output->isVerbose() ? (mb_strlen($job->getJobId()) + 1) : 0 |
| 232 | + ) - mb_strlen($runTime) - 31, 0); |
228 | 233 |
|
229 | 234 | $this->output->write(' '.str_repeat('<fg=gray>.</>', $dots));
|
230 | 235 | $this->output->write(" <fg=gray>$runTime</>");
|
231 | 236 |
|
232 |
| - $this->output->writeln(match ($this->latestStatus = $status) { |
| 237 | + $this->output->writeln(match ($status) { |
233 | 238 | 'success' => ' <fg=green;options=bold>DONE</>',
|
234 | 239 | 'released_after_exception' => ' <fg=yellow;options=bold>FAIL</>',
|
235 | 240 | default => ' <fg=red;options=bold>FAIL</>',
|
|
0 commit comments