Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@achrafAa

Description

@achrafAa
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.