mehdi
mehdi

Reputation: 1150

when celery task will be execute if we call task with .delay()

my friends all the time talking about doing time-consuming task with celery .since i haven't computer science i can't get exactly about time of execution of celery task . in celery document talking about daemon when calling .delay() but i can't found what is daemon and finally when exactly celery task will be execute if we call it by .delay() ? :)

for example if i have below code when my_task will be execute? function.py:

def test():
    my_task.delay()
    while second<10:
       second += 1 # assume this part take a second

1-exactly when test() function finished (about 10 second after test() called)

2-in the middle of while loop

3- after finished test() and when requests wasn't too many and server have time and resources to do task!! (maybe celery is intelligent and know the best time for execute task)

4- whenever want :)

5- correct way that i don't pointed to . :)

if it's depending to configuration i must tell i used default configuration from celery documentation.thank you.

Upvotes: 3

Views: 2388

Answers (1)

RaideR
RaideR

Reputation: 947

Imagine that you do not have this task alone but several ones. You put all these tasks on a queue if you invoke it with my_task.delay(). Now there are several workers which just picks the first open task and will execute them.

So the right answer would be "Whenever the responsible worker is free". This could be immediately just before you go into your while second<10:-loop but could also take several seconds or minutes if the worker is currently busy.

Upvotes: 4

Related Questions