Skip to content

Commit 31fe93e

Browse files
committed
Fix error when scheduler has job using ::class
1 parent c81387e commit 31fe93e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Commands/SendSchedulerTasksCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Kapersoft\Knocker\Commands;
66

7+
use RuntimeException;
78
use Closure;
89
use Illuminate\Console\Command;
910
use Illuminate\Console\Scheduling\CallbackEvent;
@@ -96,8 +97,11 @@ private function getCallbackCommand(CallbackEvent $event): string
9697
$closureVariables = $function->getClosureUsedVariables();
9798

9899
if ($closureCalledClass->getName() === \Illuminate\Console\Scheduling\Schedule::class && isset($closureVariables['job'])) {
99-
return $closureVariables['job']::class;
100-
100+
return match (true) {
101+
is_string($closureVariables['job']) => $closureVariables['job'],
102+
is_object($closureVariables['job']) => $closureVariables['job']::class,
103+
default => throw new RuntimeException('Invalid job type'),
104+
};
101105
}
102106

103107
return sprintf(

tests/SendSchedulerTasksCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
Schedule::job(new SendEmails)
4545
->description('Job SendEmails')
4646
->hourlyAt('35');
47+
Schedule::job(SendEmails::class)
48+
->monthlyOn(1, '06:00')
49+
->timezone('Europe/Amsterdam');
4750

4851
Http::fake([
4952
'https://knocker.laravel.cloud/api/v1/schedulerTasks' => Http::response([
@@ -94,6 +97,12 @@
9497
'description' => 'Job SendEmails',
9598
'timezone' => 'UTC',
9699
],
100+
[
101+
'cron_expression' => '0 6 1 * *',
102+
'command' => 'Kapersoft\Knocker\Tests\Fixtures\SendEmails',
103+
'description' => 'Kapersoft\Knocker\Tests\Fixtures\SendEmails',
104+
'timezone' => 'Europe/Amsterdam',
105+
],
97106
],
98107
];
99108
});

0 commit comments

Comments
 (0)