简体   繁体   English

当我们用.delay()调用任务时芹菜任务将被执行

[英]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() ? 在celery文件中,在调用.delay()时讨论守护进程,但是我找不到什么是守护进程,最后如果我们通过.delay()调用芹菜任务将会执行它? :) :)

for example if i have below code when my_task will be execute? 例如,当我执行my_task时,我有以下代码? function.py: 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) 1 - 完全在test()函数完成时(在test()调用后约10秒)

2-in the middle of while loop 2 - 在while loop中间

3- after finished test() and when requests wasn't too many and server have time and resources to do task!! 3-完成test()和请求不是太多,服务器有时间和资源来完成任务! (maybe celery is intelligent and know the best time for execute task) (也许芹菜很聪明,知道执行任务的最佳时间)

4- whenever want :) 4-每当想要:)

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. 如果它取决于配置我必须告诉我使用芹菜文档的默认配置。谢谢你。

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() . 如果使用my_task.delay()调用它, 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. 这可能会在您进入while second<10: -loop之前立即进行,但如果工作人员当前正忙,也可能需要几秒钟或几分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM