Skip to content

Scheduled Task Failure Events Not Consistently Dispatched (Including runInBackground Cases) #55614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
achrafAa opened this issue Apr 30, 2025 · 1 comment

Comments

@achrafAa
Copy link
Contributor

Laravel Version

12.x

PHP Version

8.4

Database Driver & Version

No response

Description

Description

Two related issues exist with scheduled task failure events:

  1. **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.

  2. **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

  1. All task failures (including background jobs) should dispatch ScheduledTaskFailed

  2. Background tasks should properly report their status without throwing scheduler exceptions

Actual Behavior

  1. Some failure modes still don't trigger the event

  2. Background tasks cause scheduler exceptions instead of clean failure reporting

Root Cause

  1. Incomplete failure state handling in the scheduler's execution flow

  2. Background process status checking isn't properly integrated with the event system

Suggested Solution

Need to:

  1. Expand the scheduler's failure detection to cover all edge cases

  2. Properly handle background process status returns

  3. 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

@achrafAa
Copy link
Contributor Author

PR : WIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant