Reputation: 4656
Building on this question:
Django Celery Time Limit Exceeded?
I have some tasks that may run for sometime. However, most tasks should not take more then a few seconds. I don't want to set the global timeout to account for those long running tasks. Rather, I would like to have a global hard timelimit that is short, and manually adjust the tasks that I need to have a longer timeout.
When decorating the task with @task I did @task(timeout=None) and yet, that task still hit a timeout of 300 seconds. I called the task with task_function.delay(args).
Is there a way to call a task and customize it's timeout?
Upvotes: 2
Views: 7884
Reputation: 10846
This issue addresses the case when you can call a task with custom timeouts. It is implemented in issue802 branch but isn't in master yet. You can merge it with master and use the desired functionality.
With this patch, you can pass timeouts when calling tasks.
tasks.add.apply_async(args=[1,2], soft_timeout=2, timeout=5)
Upvotes: 3
Reputation: 752
What version of celery are you running? The current stable docs list time_limit
as the correct argument for setting the timeout on a task and that the worker default will be used if no time limit is provided. To set a long (e.g. 60 minute) timeout on a task you can use:
@task(time_limit=3600)
def mytask():
...
Alternatively, you can use apply_async to change the time limit when you call the task:
mytask.apply_async(time_limit=3600, args=args)
Upvotes: 2