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

时间:2022-06-05 01:23:10

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.

我有任务:recursive_task将安排相同的任务在5秒后执行,但如果由于某种原因此任务崩溃,则需要再次重新运行。我几乎抓住了每一个场景,但你永远不知道将来会发生什么。

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?

我首先做了一个重复的任务:manage_tasks检查recursive_task的状态,并检查它是否长时间没有运行,是否成功完成,但这感觉不对。那你怎么解决这个问题呢?

2 个解决方案

#1


1  

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.

尝试acks_late设置CELERY_ACKS_LATE,它将在任务执行后确认任务消息。有了这个,您可以更轻松地重新运行任务。

#2


0  

I can suggest to take a look at python signals:

我建议看看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

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.

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

#1


1  

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.

尝试acks_late设置CELERY_ACKS_LATE,它将在任务执行后确认任务消息。有了这个,您可以更轻松地重新运行任务。

#2


0  

I can suggest to take a look at python signals:

我建议看看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

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.

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