Feature #87806

Scheduler: Send email on error

Added by Sven Burkert almost 2 years ago. Updated 9 months ago.

Status:
Accepted
Priority:
Should have
Assignee:
-
Category:
scheduler
Start date:
2019-02-27
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
scheduler, email, report, error
Complexity:
medium
Sprint Focus:

Description

It would be very helpful if a website maintainer is informed by email, when a scheduler task fails.
Right now, there's no setting for that, right? Not even an extension is existing for that.
If you don't want to provide this feature, perhaps at least a hook / signal slot could be provided, after a scheduler task failed.


Related issues

Related to TYPO3 Core - Epic #88027: Properly handle Hooks/Signals and EventsIn ProgressBenni Mack2019-03-28

Actions
#1

Updated by Bernd Wilke almost 2 years ago

As the scheduler is called by cron: the owner of the cron task will be mailed on an error or any output.

#2

Updated by Sven Burkert over 1 year ago

Hi Bernd, thank you for the hint.
I also know that you can send the output of a cronjob to an email address like this way:

MAILTO=email@example.com
0 */2 * * * /bin/mycron.sh

But are you sure, there's output from the TYPO3 scheduler? The scheduler jobs are called in a try-catch-block and errors are catched and handled by TYPO3 (to show them in BE module "Scheduler"). I don't think that the cronjob/cron task realizes that an error occured.
On my server, no email was sent, after an error occured in several scheduler jobs, but the failed jobs are marked in red in TYPO3 BE.

#3

Updated by Benni Mack over 1 year ago

  • Related to Epic #88027: Properly handle Hooks/Signals and Events added
#4

Updated by Christoph Lehmann about 1 year ago

File: typo3/typo3/sysext/scheduler/Classes/Command/SchedulerCommand.php

                try {
                    $this->scheduler->executeTask($task);
                } catch (\Exception $e) {
                    // We ignore any exception that may have been thrown during execution,
                    // as this is a background process.
                    // The exception message has been recorded to the database anyway
                    continue;
                }

With this code there is no unhacky way to get informed about failed tasks.

Cronjobs normally output some message on errorr. If you are not interested in the output you can redirect it to /dev/null.

#5

Updated by Helmut Hummel about 1 year ago

I agree that error handling in Scheduler can be improved.

I'd also agree that it would be fine to output error messages to stderr when a task failed.
However I'm not sure whether it would be good to let the whole command to return an error code when one task failed.
And that is because I think that handling of failure of a single task could be seen as intended behavior of a scheduler.

The unix cronjob runner also has defined behavior what happens when a single cronjob fails and that behavior does not include failing itself,
but catching the failure of the cronjob and dispatching it via mail.

The same behavior should be consider for scheduler. Maybe output the failure, but not exiting with an error code.

So what is missing here is properly logging of the error within the scheduler class here: https://github.com/TYPO3/TYPO3.CMS/blob/9af6dc4226998e76c80b5a789d2bc5c398065b3c/typo3/sysext/scheduler/Classes/Scheduler.php#L183-L186

This would allow to react accordingly within a log writer and send out mails, push the error to a central place where application error are collected.

All that (and some more things) you get when using my scheduler alternative already now.

But adding an additional logging call when a task failed should also be easy and would improve the situation for TYPO3 Scheduler a lot.

#6

Updated by Helmut Hummel about 1 year ago

I'm not sure if we'd really need to provide an event as well if proper logging is in place, but it certainly would not harm to additionally add a way to handle the failure by adding an event except from logging to a target.

#7

Updated by Christoph Lehmann about 1 year ago

The unix cronjob runner also has defined behavior what happens when a single cronjob fails and that behavior does not include failing itself,
but catching the failure of the cronjob and dispatching it via mail.

The same behavior should be consider for scheduler. Maybe output the failure, but not exiting with an error code.

Exactly.

So what is missing here is properly logging of the error within the scheduler class here: https://github.com/TYPO3/TYPO3.CMS/blob/9af6dc4226998e76c80b5a789d2bc5c398065b3c/typo3/sysext/scheduler/Classes/Scheduler.php#L183-L186
This would allow to react accordingly within a log writer and send out mails, push the error to a central place where application error are collected.

Logging via logwriter can be optional in my opinion, but it should receive the whole exception (with stacktrace, etc.) not only a log message

#8

Updated by Christoph Lehmann about 1 year ago

Another possibility we can think about is to have more options i) in a scheduler task or ii) as globally via EXTCONF

- Errors to sterr
- Errors to Mailaddress (or Mailaddress of be user)
- Retry in X Minutes

#9

Updated by Georg Ringer 9 months ago

  • Status changed from New to Accepted
  • Target version set to Candidate for Major Version

Also available in: Atom PDF