Project

General

Profile

Actions

Feature #87806

closed

Scheduler: Send email on error

Added by Sven Burkert over 5 years ago. Updated 10 months ago.

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

100%

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 3 (1 open2 closed)

Related to TYPO3 Core - Epic #88027: Properly handle Hooks/Signals and EventsClosedBenni Mack2022-04-22

Actions
Related to TYPO3 Core - Feature #87451: Allow execution of multiple scheduler tasks in command lineClosed2019-01-15

Actions
Precedes TYPO3 Core - Feature #100946: Scheduler: More details via mail on failed taskUnder Review

Actions
Actions #1

Updated by Bernd Wilke over 5 years ago

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

Actions #2

Updated by Sven Burkert over 5 years 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.

Actions #3

Updated by Benni Mack over 5 years ago

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

Updated by Christoph Lehmann about 5 years 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.

Actions #5

Updated by Helmut Hummel about 5 years 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.

Actions #6

Updated by Helmut Hummel about 5 years 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.

Actions #7

Updated by Christoph Lehmann about 5 years 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

Actions #8

Updated by Christoph Lehmann about 5 years 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

Actions #9

Updated by Georg Ringer over 4 years ago

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

Updated by varioous OG over 3 years ago

+1

I would suggest an executed-method in the scheduler (AbstractTask) that will be called after the task is finished with the result

public function finished(bool success, $e) {
  //will be called from TYPO3 Core after task was executed
  .....
}

Actions #11

Updated by Gerrit Code Review over 1 year ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77936

Actions #12

Updated by Markus Klein over 1 year ago

  • Related to Feature #87451: Allow execution of multiple scheduler tasks in command line added
Actions #13

Updated by Gerrit Code Review over 1 year ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77936

Actions #14

Updated by Gerrit Code Review over 1 year ago

Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78220

Actions #15

Updated by Gerrit Code Review over 1 year ago

Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77936

Actions #16

Updated by Markus Klein over 1 year ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #17

Updated by Philipp Kitzberger over 1 year ago

  • Precedes Feature #100946: Scheduler: More details via mail on failed task added
Actions #18

Updated by Benni Mack 10 months ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF