Sergey
Sergey

Reputation: 21191

Celery: can I not just limit a task but do not even put in a queue if 1 is already running?

I have this task:

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

and I start it from a Python function:

very_long_process.delay() 

I don't want to start another one and even queue it if another instance of this task is already running.

How can I check if there is 1 running already (and get its ID)?

Upvotes: 0

Views: 111

Answers (1)

pavel_form
pavel_form

Reputation: 1790

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

Upvotes: 1

Related Questions