如果任务没有运行超过 10 分钟,如何重新安排任务?
我有 task:recursive_task 它将安排相同的任务在 5 秒后执行,但如果由于某种原因该任务崩溃,则需要再次重新运行。 我几乎捕捉到了所有场景,但你永远不知道未来会发生什么。
我首先做了一个重复的任务:manage_tasks,它检查 recursive_task 的状态,并检查它是否长时间没有运行以及是否成功完成,但这感觉不对。那么你会如何解决这个问题呢?
I have task:recursive_task which will schedule the same task to be executed 5 seconds later, but if for some reason this task crashes it needs to be rerun again.
I catched nearly every scenario but you never know what will happen in the future.
I first made a repeated task:manage_tasks which checks the status of recursive_task and will check if it didn't run for a long time and if it was succesfully completed, but this didn't feel right. So how would you solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 acks_late 设置 CELERY_ACKS_LATE,它将确认任务消息任务执行后。有了这个,您可以更轻松地重新运行您的任务。
Try acks_late setting CELERY_ACKS_LATE, it will have the task messages be acknowledged after the task has been executed. With this you may be able to rerun your tasks more easily.
我建议看一下 python 信号:
http://docs.python.org/library/ signal.html
其中:
使用信号,您可以将处理程序设置为在您想要的任何时间后执行。然后,这是通过处理程序重新运行脚本的直接方法。
I can suggest to take a look at python signals:
http://docs.python.org/library/signal.html
Where:
With signals, you can set the handler to be executed after any time, you want. Then it's a straight way to rerun your script through the handler.