Skip to content

Commit

Permalink
Show Job class name instead of closure. (#41535)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiCO2k committed Mar 17, 2022
1 parent 81374b3 commit 0256484
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function handle(Schedule $schedule)
$expression = $this->formatCronExpression($event->expression, $expressionSpacing);

$command = $event->command;
$description = $event->description;

if (! $this->output->isVerbose()) {
$command = str_replace(
Expand All @@ -62,7 +63,12 @@ public function handle(Schedule $schedule)
}

if ($event instanceof CallbackEvent) {
$command = 'Closure at: '.$this->getClosureLocation($event);
if (class_exists($event->description)) {
$command = $event->description;
$description = '';
} else {
$command = 'Closure at: '.$this->getClosureLocation($event);
}
}

$command = mb_strlen($command) > 1 ? "{$command} " : '';
Expand Down Expand Up @@ -95,11 +101,11 @@ public function handle(Schedule $schedule)
$hasMutex,
$nextDueDateLabel,
$nextDueDate
), $this->output->isVerbose() && mb_strlen($event->description) > 1 ? sprintf(
), $this->output->isVerbose() && mb_strlen($description) > 1 ? sprintf(
' <fg=#6C7280>%s%s %s</>',
str_repeat(' ', mb_strlen($expression) + 2),
'⇁',
$event->description
$description
) : ''];
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testDisplaySchedule()
$this->schedule->command(FooCommand::class)->quarterly();
$this->schedule->command('inspire')->twiceDaily(14, 18);
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
$this->schedule->job(FooJob::class)->everyMinute();

$this->schedule->call(fn () => '')->everyMinute();
$closureLineNumber = __LINE__ - 1;
Expand All @@ -36,6 +37,7 @@ public function testDisplaySchedule()
->expectsOutput(' 0 0 1 1-12/3 * php artisan foo:command .... Next Due: 3 months from now')
->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now')
->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now');
}

Expand Down Expand Up @@ -65,3 +67,7 @@ class FooCommand extends Command

protected $description = 'This is the description of the command.';
}

class FooJob
{
}

0 comments on commit 0256484

Please sign in to comment.