Celery:我不仅可以限制任务,但如果1已经运行,甚至不会排队吗?

时间:2014-12-22 12:18:29

标签: python celery

我有这个任务:

@app.task(rate_limit='1/m')
def very_long_process():
    pass  # not very long, lol

我从Python函数开始:

very_long_process.delay() 

如果此任务的另一个实例已在运行,我不想启动另一个甚至排队。

如何检查是否已有1个正在运行(并获取其ID)?

1 个答案:

答案 0 :(得分:1)

async_result = very_long_process.delay()
task_id = async_result.id
task_status = async_result.status
task_finished = async_result.ready() # to check if task finished its execution
task_succeeded = async_result.successful() # to check if task finished its execution with success