Feature #87806
closedScheduler: Send email on error
Added by Sven Burkert over 5 years ago. Updated 7 months ago.
100%
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.
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.
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.
Updated by Benni Mack over 5 years ago
- Related to Epic #88027: Properly handle Hooks/Signals and Events added
Updated by Christoph Lehmann almost 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.
Updated by Helmut Hummel almost 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.
Updated by Helmut Hummel almost 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.
Updated by Christoph Lehmann almost 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
Updated by Christoph Lehmann almost 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
Updated by Georg Ringer over 4 years ago
- Status changed from New to Accepted
- Target version set to Candidate for Major Version
Updated by varioous OG about 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
.....
}
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
Updated by Markus Klein over 1 year ago
- Related to Feature #87451: Allow execution of multiple scheduler tasks in command line added
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
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
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
Updated by Markus Klein over 1 year ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 65428ad3f4c9f2c6dd5a14d6882351e55ca4e016.
Updated by Philipp Kitzberger about 1 year ago
- Precedes Feature #100946: Scheduler: More details via mail on failed task added