如果任务没有运行超过 10 分钟,如何重新安排任务?

发布于 2024-12-10 16:41:32 字数 203 浏览 4 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疧_╮線 2024-12-17 16:41:32

尝试 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.

似最初 2024-12-17 16:41:32

我建议看一下 python 信号:

http://docs.python.org/library/ signal.html

import signal

# Set the signal handler and an alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(900) # 15 miutes
# some_function()

signal.alarm(0)          # Disable the alarm

其中:

def handler(signum, frame):
    # do something
    sys.exit(1)

使用信号,您可以将处理程序设置为在您想要的任何时间后执行。然后,这是通过处理程序重新运行脚本的直接方法。

I can suggest to take a look at python signals:

http://docs.python.org/library/signal.html

import signal

# Set the signal handler and an alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(900) # 15 miutes
# some_function()

signal.alarm(0)          # Disable the alarm

Where:

def handler(signum, frame):
    # do something
    sys.exit(1)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文