Description
Laravel Version
12.x
PHP Version
8.2+
Database Driver & Version
PostgreSQL
Description
Description
Two related issues exist with scheduled task failure events:
-
**Original Issue:**The ScheduledTaskFailed event doesn't dispatch consistently across all failure modes (exceptions, non-zero exit codes, background/system failures). While [12.x]
ScheduledTaskFailed
not dispatched on scheduled task failing #55572 addressed part of this, there's still inconsistent behavior. thus it was reverted. -
**New runInBackground Issue:**When using ->runInBackground(), commands don't properly return status codes, causing exceptions in the scheduler. This prevents proper failure event dispatching for background tasks.
Steps to Reproduce
For Issue #1:
// routes/console.php
Artisan::command('failing-command', function () {
throw new Exception('Should trigger failure event');
})->everyMinute();
// AppServiceProvider.php
Event::listen(ScheduledTaskFailed::class, function () {
Log::error('Failure event not received');
});
For Issue #2:
// routes/console.php
Schedule::command('app:command-exit')
->everyTenSeconds()
->runInBackground(); // Causes exceptions
Expected Behavior
-
All task failures (including background jobs) should dispatch ScheduledTaskFailed
-
Background tasks should properly report their status without throwing scheduler exceptions
Actual Behavior
-
Some failure modes still don't trigger the event
-
Background tasks cause scheduler exceptions instead of clean failure reporting
Root Cause
-
Incomplete failure state handling in the scheduler's execution flow
-
Background process status checking isn't properly integrated with the event system
Suggested Solution
Need to:
-
Expand the scheduler's failure detection to cover all edge cases
-
Properly handle background process status returns
-
Ensure consistent event dispatching regardless of execution method
Steps To Reproduce
// routes/console.php
Artisan::command('failing-command', function () {
throw new Exception('Should trigger failure event');
})->everyMinute();
// AppServiceProvider.php
Event::listen(ScheduledTaskFailed::class, function () {
Log::error('Failure event not received');
});
and for the second issue
// routes/console.php
Schedule::command('app:command-exit')
->everyTenSeconds()
->runInBackground(); // Causes exceptions