Setting Time Limit on specific task with celery

我的梦境 提交于 2019-11-28 18:33:50
mher

You can set task time limits (hard and/or soft) either while defining a task or while calling.

from celery.exceptions import SoftTimeLimitExceeded

@celery.task(time_limit=20)
def mytask():
    try:
        return do_work()
    except SoftTimeLimitExceeded:
        cleanup_in_a_hurry()

or

mytask.apply_async(args=[], kwargs={}, time_limit=30, soft_time_limit=10)

This is an example with decorator for an specific Task and Celery 3.1.23 using soft_time_limit=10000

@task(bind=True, default_retry_delay=30, max_retries=3, soft_time_limit=10000)
def process_task(self, task_instance):
   """Task processing."""
        pass
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!