You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should the ScheduledTaskFinished event be dispatched if the scheduled task fails?
Context
As it stands, there's a debate about whether it's correct to dispatch the ScheduledTaskFinished event when a task throws an exception or returns a non-zero exit code.
In my recent PR #55624, I tried to improve the current behavior while avoiding breaking changes. Here's a summary of the current vs proposed behavior:
before this fix :
Scenario
ScheduledTaskFinished
ScheduledTaskFailed
Command runs and throws an exception within itself
✅ Dispatched
❌ Not dispatched
Command runs and returns non-zero $exitCode
✅ Dispatched
❌ Not dispatched
$event->run($this->laravel); itself throws
❌ Not dispatched
✅ Dispatched
after the fix :
Scenario
ScheduledTaskFinished
ScheduledTaskFailed
Command runs and throws an exception within itself
✅ Dispatched
✅ Dispatched
Command runs and returns non-zero $exitCode
✅ Dispatched
✅ Dispatched
$event->run($this->laravel); itself throws
❌ Not dispatched
✅ Dispatched
Options Considered
1️⃣ First Proposition
✅ Always dispatch ScheduledTaskFinished
✅ Dispatch ScheduledTaskSucceeded or ScheduledTaskFailed depending on outcome
No visibility into whether task succeeded—only that it didn’t fail.
Could be confusing for observers or logs.
Eliminates granularity between succeeded and finished.
✅ Recommendation
First Proposition is the most complete and traceable approach.
It ensures:
Every task emits a final Finished state.
It’s clear if a task succeeded or failed.
Observability and logging are optimal for debugging and monitoring.
This gives the best traceability, clean separation of concern, and ensures that listeners can react to the completion of a task—success or failure—without ambiguity.
🗣️ What do you think?
1 Should ScheduledTaskFinished always be dispatched, even after failure?
2 Do you rely on it in your cleanup, observability, or monitoring systems?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The Question
Should the
ScheduledTaskFinished
event be dispatched if the scheduled task fails?Context
As it stands, there's a debate about whether it's correct to dispatch the
ScheduledTaskFinished
event when a task throws an exception or returns a non-zero exit code.In my recent PR #55624, I tried to improve the current behavior while avoiding breaking changes. Here's a summary of the current vs proposed behavior:
ScheduledTaskFinished
ScheduledTaskFailed
$event->run($this->laravel);
itself throwsScheduledTaskFinished
ScheduledTaskFailed
$event->run($this->laravel);
itself throwsOptions Considered
1️⃣ First Proposition
✅ Pros:
❌ Cons:
ScheduledTaskFinished
even after aScheduledTaskFailed
, potentially duplicating effort.2️⃣ Second Proposition
✅ Pros:
Finished
dispatch after failure.❌ Cons:
Finished
event).3️⃣ Third Proposition
✅ Pros:
❌ Cons:
succeeded
andfinished
.✅ Recommendation
First Proposition is the most complete and traceable approach.
It ensures:
Finished
state.This gives the best traceability, clean separation of concern, and ensures that listeners can react to the completion of a task—success or failure—without ambiguity.
🗣️ What do you think?
1 Should ScheduledTaskFinished always be dispatched, even after failure?
2 Do you rely on it in your cleanup, observability, or monitoring systems?
Would changing this behavior break your workflow?
Looking forward to your thoughts and use cases.
@achrafAa
1 vote ·
Beta Was this translation helpful? Give feedback.
All reactions