Magento Cron 脚本终止时重试
我遇到了 Magento cron 的问题。我在 Helper 类中有一个通过 cron 触发的方法,但在某些时候,如果该方法逻辑中的文件存在问题,我会以错误代码退出(即 error(1)
)。方法正在使用。看起来,如果该方法没有正常结束,Magento cron 会尝试重新运行脚本,直到达到配置中设置的“如果未运行则错过”限制。
我尝试使用成功代码退出(即 exit(0)
),但这似乎没有帮助。有没有一种优雅的方法可以做到这一点,以便 Magento 在出错时不会尝试重新运行脚本?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
user923990 在他自己的问题中给出了这个答案:
将代码包装在 try-catch 中并允许其正常退出会关闭 cron 作业。使用
die()
或任何类型的exit()
(甚至exit(0)
)退出会导致 Magento 认为作业已失败,并且它会尝试再次运行它。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.