Skip to content
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

[7.x] Catch and report exceptions thrown during schedule run execution #32461

Merged
merged 1 commit into from Apr 20, 2020
Merged

[7.x] Catch and report exceptions thrown during schedule run execution #32461

merged 1 commit into from Apr 20, 2020

Conversation

michaeldyrynda
Copy link
Contributor

@michaeldyrynda michaeldyrynda commented Apr 20, 2020

As the task scheduler executes scheduled events sequentially, if any of the tasks were to raise a Throwable, any subsequent tasks in that execution thread will not be processed.

Consider the following task schedule:

$schedule->call(function () {
    // Some task logic
}}->everyMinute();

$schedule->call(function () {
    throw new Exception('Some task that throws an exception');
})->everyMinute();

$schedule->call(function () {
    // Some task that is never run
})->everyMinute();

Whilst your error reporting tool or logging channel would likely report this occurrence, none of the tasks subsequent to the Throwable would be run at all, which is undesirable.

In order to allow task execution to continue to flow, whilst also reporting the exception to your error reporting tool or logging channel, catching and reporting the Throwable will be sufficient to allow the remaining tasks to execute.

I've also moved the dispatch of the ScheduledTaskFinished event and setting of eventsRan inside the try block, as a Throwable being raised indicates that the task did not finish running, and as such should not be flagged as having been run.

@taylorotwell taylorotwell merged commit ff4cbbc into laravel:7.x Apr 20, 2020
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

Successfully merging this pull request may close these issues.

None yet

4 participants