-
Notifications
You must be signed in to change notification settings - Fork 11.4k
ScheduledTaskFailed
event is not dispatched when scheduled task is failing
#55352
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
Comments
ScheduledTaskFailed
is not fired when scheduled task is failingScheduledTaskFailed
event is not dispatched when scheduled task is failing
Since Laravel runs scheduled commands as a background process, exceptions don’t bubble up, and ScheduledTaskFailed is never fired. Suggested Fix: if ($event->task->exitCode !== 0) { |
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
I have the same issue in Laravel 12.x. I'm still making some tests, but so far, I created a Listener that handles both "ScheduledTaskFinished" and "ScheduledTaskFinished" and in the handler, I test the exit code for non-success to do the proper error handling. Something like this: public function handle(ScheduledTaskFinished|ScheduledTaskFailed $event,): void
{
if ($event instanceof ScheduledTaskFailed || $event->task->exitCode != 0) {
$this->handleFail($event);
}
}
protected function handleFail($event)
{
//...
} |
@erickcomp In my case, |
In my case, the |
@erickcomp what the laravel version you are using, is it 12.x ? |
@sagautam5 . Yup, it's 12.3. |
@erickcomp This means issue is on version 11.x and has been fixed on laravel 12.x, right ? |
@sagautam5 No, it does not. |
Hey 👋 I’ve created a PR to resolve this issue by ensuring the ScheduledTaskFailed event is dispatched for all failure cases — including exceptions, non-zero exit codes, and background/system-level failures. PR: #https://github.com/laravel/framework/pull/55551 This should make failure handling much more consistent for monitoring, alerts, and debugging workflows. Let me know if any adjustments are needed! ✅ |
@achrafAa it seems this will fix my issue, hopefully it will get merged very soon ! |
@sagautam5 I created a PR for both version 11 and 12 also joined some screenshots of testing please add a comment to the PR or upvote : |
@sagautam5 @erickcomp up and comment again on this #55572 |
@sagautam5 you can now close the issue as its addressed in this PR #55572 and Merged 🚀 |
@achrafAa What should I do ? |
@sagautam5 those are the previous ones, the merged one is #55572 |
I believe this change introduced a bug: #55609 |
@alexey-m-ukolov more like uncovered some hidden bugs |
@sagautam5 the issue is still here as the PR was reverted for uncovering other issues 👀 |
I'm a bit confused regarding the current status: => First PR was reject by Taylor; Is that it, @achrafAa ? If so, is there any way we (the ones interested in listening to this event,) can help? Anyway, thanks for all the efforts you're putting to resolve this bug! |
@erickcomp The first PR was rejected due to concerns about potential issues.The second PR was accepted after sharing test results, but later reverted after identifying problems with the runInBackground commands—specifically, they were throwing exceptions due to returning null or an exit code that the fix interpreted as a failure, since the commands were running in a separate shell. This PR #55624 addresses the core issue: ensuring failure detection for foreground scheduled commands, without interfering with or affecting background tasks, which require separate handling outside the scope of this fix. a comment and react can help the PR get noticed and most welcome, I have used Laravel since 2013 and I am interested in giving back to the community and helping each other 😁. |
Uh oh!
There was an error while loading. Please reload this page.
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 butScheduledTaskFailed
is not dispatched even when scheduled task is failing.I have also looked into the implementation in framework:
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
routes/console.php
that runs every minute & failsphp artisan schedule:run
Console Error:
But nothing logged into laravel log.
The text was updated successfully, but these errors were encountered: