5

I was wondering if there is an option in Magento ver. 1.9.2.2 to get an email if cron is not running or more important if a cronjob fails. I didn't find any configuration in backend nor any information here on StackExchange.

If I do not miss anything and there is no setting for it, how can I achieve it? Probably by writing an extension, but is there any kind of event what gets triggered when a cronjob fails? Thank you.

  • 4
    Possible duplicate of configuring cron jobs for Magento on Centos Magento 1.7 – MagenX Mar 9 '16 at 12:16
  • MAILTO=me@domain.com – MagenX Mar 9 '16 at 12:16
  • @MagenX How does that answer this question? – Fabian Schmengler Mar 9 '16 at 22:15
  • first you follow that link, then you put this comment together, and you get the idea :) – MagenX Mar 10 '16 at 8:05
  • 2
    The question above is not a duplicate in my opinion and the question is a valid one. Leave open. – Anna Völkl Mar 10 '16 at 11:25
3

Its not native, but its totally possible to implement. On MageStack we use a cron wrapper to secure the cron process, provide support for Aoe_Scheduler and allow error capture.

Whilst I won't copy the source code here, the basic concept is pretty simple. You iterate over the different task types and capture the output from stderr - then send an email if it fails.

EMAIL_RECIPIENT="you@youremail.com"
LOG_FILE="var/log/cron.log"
CRON_ARGS=( "-mdefault 1" "-malways 1" )

RES=5
for ARGS in "${CRON_ARGS[@]}"; do
  php cron.php $ARGS >> $LOG_FILE 2>&1
  [ $RES -ne 0 ] && RES=$?
done

if [ $RES -ne 0 ] && [[ ! "$EMAIL_RECIPIENT" == "" ]]; then
  echo "Something went wrong with the cron, see attached" | mutt -s "Cron error" -a "$LOG_FILE" -- $EMAIL_RECIPIENT
fi
| improve this answer | |
  • Very interesting approach/solution. Thanks for that! – Xavin Mar 21 '16 at 18:46
3

No, there is nothing built in like that, you'll need to implement your own monitoring. And don't try to do it with a Magento observer, since it won't be able to catch a non-running or crashed cronjob.

As a simple service just for cronjob monitoring I can recommend https://healthchecks.io/ - you add a ping to your cronjobs and can configure notifications when there was no ping for a certain time.

| improve this answer | |
0

The same thing happened to a client of mine. They wanted to be notified not just of failures but they wanted to know how long jobs were taking to run and get notified of errors. I couldn't find something that fit what they wanted so I ended up building a small (free) notification service that checks to make sure that schedules are running on time, but also captures elapsed times and graphs them out nicely for you. It's the Job Heath Data Vault, has Magento 1 and Magento 2 adapters and is free to use.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.