[13.x] Fix scheduled callbacks rethrowing a previous exception on later runs
Merged
SU
21d ago+30+30+01234567890123456789-0-0-0123456789
When a scheduled closure throws once, every later run of that event in the same schedule:run process throws the same exception again, even when the callback succeeds. This shows up with sub-minute tasks, since schedule:run keeps running the same event object for the whole minute:
Schedule::call(function () {
// fails once because an API is briefly unavailable, then succeeds
})->everyTenSeconds();
After the first failure, the following runs succeed but still report the old exception and dispatch ScheduledTaskFailed, so you get the same error reported up to six times a minute and failure notifications for runs that worked.
CallbackEvent::execute() stores the exception on the event but never clears it, and run() throws it whenever it's set. This clears it at the start of each run.