I’m having an issue with a Magento cron. I have a method in a Helper Class firing via the cron, but at some points the the method logic, I exit with an error code (ie error(1)) if there are issues with files that the method is working with. It seems that if the method doesn’t end normally, Magento cron tries to re-run the script until it hits the ‘Missed if Not run In’ limit set in the config.
I tried exiting with a success code (ie exit(0)), but that doesn’t seem to help. Is there a graceful way to do this so that Magento doesn’t try to re-run the script if it errors-out?
user923990 gave this answer in his own question:
Wrapping the code in a try-catch and allowing it to exit normally closes out the cron job. Exiting with a
die()or any sort ofexit()(evenexit(0)) causes Magento to think the job has failed and it will try to run it again.