Sam Stoelinga
Sam Stoelinga

Reputation: 5021

How to reschedule a task if it hasn't been running for more than 10 minutes?

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?

Upvotes: 1

Views: 761

Answers (2)

lwg643
lwg643

Reputation: 121

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.

Upvotes: 1

Gandi
Gandi

Reputation: 3652

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.

Upvotes: 0

Related Questions