Closed
Description
Laravel Version
11.0^
PHP Version
8.4
Database Driver & Version
I am using Postgres DB
Description
I was trying to listen the laravel builtin event ScheduledTaskFailed
to send notifications like email/slack etc. when scheduled command is failed in the application.
However all other events such as ScheduledTaskFinished
, ScheduledTaskSkipped
, ScheduledTaskStarting
are dispatched correctly but ScheduledTaskFailed
is not dispatched even when scheduled task is failing.
I have also looked into the implementation in framework:
try {
$event->run($this->laravel);
$this->dispatcher->dispatch(new ScheduledTaskFinished(
$event,
round(microtime(true) - $start, 2)
));
$this->eventsRan = true;
} catch (Throwable $e) {
$this->dispatcher->dispatch(new ScheduledTaskFailed($event, $e));
$this->handler->report($e);
}
In this section, implementation inside catch is never executed even when failure of scheduled task.
Is there anything I am missing or misunderstood in it ?
Steps To Reproduce
- Add following listener logic inside boot method of app service provider
use Illuminate\Console\Events\ScheduledTaskFailed;
use Illuminate\Support\Facades\Event;
Event::listen(ScheduledTaskFailed::class, function () {
logger('Scheduled task failed');
});
- Add example task to
routes/console.php
that runs every minute & fails
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
throw new \Exception('Inspirational quote sent!');
})->purpose('Display an inspiring quote')->everyMinute();
- Run Scheduler
php artisan schedule:run
Console Error:
2025-04-10 09:55:04 Running ['artisan' inspire] .................................................................................... 774.96ms FAIL
⇂ '/usr/local/bin/php' 'artisan' inspire > '/dev/null' 2>&1
But nothing logged into laravel log.