Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery - How does countdown work?

Tags:

python

celery

I want to understand how supplying a countdown=xx affect the scheduling of the task. According to http://docs.celeryproject.org/en/latest/userguide/calling.html?highlight=countdown#eta-and-countdown, setting countdown means that the task will take atleast xx seconds to execute.

What I want to know is how it is implemented. When we supply a task with a countdown value, is the task added to the queue but no workers pick it up or the workers pick up the task but defer it's execution until atleast the countdown value expires?

like image 916
Nikhil Singh Avatar asked Sep 24 '13 09:09

Nikhil Singh


People also ask

What is Celery countdown?

countdown is a shortcut to set eta by seconds into the future. >>> result = add. apply_async(args=[10, 10], countdown=3) >>> result. get() # this takes at least 3 seconds to return 20. The task is guaranteed to be executed at some time after the specified date and time, but not necessarily at that exact time.

How does Celery ETA work?

Celery workers poll the queues and pulls available tasks. When a worker pulls a task, it removes it from the named queue and moves it to a special Redis unacked queue. The worker holds on to the task in memory, until it can process it.

How does Celery distribute work?

Celery is a distributed task queue written in Python, which works using distributed messages. Each execution unit in celery is called a task. A task can be executed concurrently on one or more servers using processes called workers.

How does Celery execute tasks?

Celery workers are worker processes that run tasks independently from one another and outside the context of your main service. Celery beat is a scheduler that orchestrates when to run tasks. You can use it to schedule periodic tasks as well.


1 Answers

The task is picked by a worker, but not acknowledged.

It means that if the power runs out, the task will be re-fetched by a different worker later.

The task's args/kwargs are kept in worker's memory until it's finished, so keep this in mind because you might run out of it really quick with lots of countdown tasks and large args/kwargs.

like image 104
Krzysztof Szularz Avatar answered Sep 26 '22 15:09

Krzysztof Szularz