Skip to content

Commit 0256484

Browse files
authored
Show Job class name instead of closure. (#41535)
1 parent 81374b3 commit 0256484

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Illuminate/Console/Scheduling/ScheduleListCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function handle(Schedule $schedule)
5252
$expression = $this->formatCronExpression($event->expression, $expressionSpacing);
5353

5454
$command = $event->command;
55+
$description = $event->description;
5556

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

6465
if ($event instanceof CallbackEvent) {
65-
$command = 'Closure at: '.$this->getClosureLocation($event);
66+
if (class_exists($event->description)) {
67+
$command = $event->description;
68+
$description = '';
69+
} else {
70+
$command = 'Closure at: '.$this->getClosureLocation($event);
71+
}
6672
}
6773

6874
$command = mb_strlen($command) > 1 ? "{$command} " : '';
@@ -95,11 +101,11 @@ public function handle(Schedule $schedule)
95101
$hasMutex,
96102
$nextDueDateLabel,
97103
$nextDueDate
98-
), $this->output->isVerbose() && mb_strlen($event->description) > 1 ? sprintf(
104+
), $this->output->isVerbose() && mb_strlen($description) > 1 ? sprintf(
99105
' <fg=#6C7280>%s%s %s</>',
100106
str_repeat(' ', mb_strlen($expression) + 2),
101107
'',
102-
$event->description
108+
$description
103109
) : ''];
104110
});
105111

tests/Integration/Console/Scheduling/ScheduleListCommandTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function testDisplaySchedule()
2626
$this->schedule->command(FooCommand::class)->quarterly();
2727
$this->schedule->command('inspire')->twiceDaily(14, 18);
2828
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
29+
$this->schedule->job(FooJob::class)->everyMinute();
2930

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

@@ -65,3 +67,7 @@ class FooCommand extends Command
6567

6668
protected $description = 'This is the description of the command.';
6769
}
70+
71+
class FooJob
72+
{
73+
}

0 commit comments

Comments
 (0)