简体   繁体   English

芹菜任务将不执行

[英]Celery task will not execute

I've followed the instruction process to installing and setting up celery , now I'm trying to execute my task. 我已经按照说明过程安装和设置celery ,现在我正在尝试执行任务。 My project tree looks like this: 我的项目树如下所示:

bin
draft1--
        |
         -------draft1 ----
                           |
                            --------celery.py
                            --------tasks.py
                            --------views.py
         -------manage.py
         -------templates

include
lib

Here's my code: 这是我的代码:

settings.py settings.py

CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//' 

celery.py celery.py

import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

app = Celery('app')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

tasks.py tasks.py

from celery import shared_task

@shared_task
def print_this():
    print('ONE MINUTE')

app.views app.views

print_this.delay()

So my celery function doesn't work, it doesn't execute the print statement. 所以我的celery函数不起作用,它不执行print语句。 What I want to do is execute the function every minute. 我想做的是每分钟执行一次功能。 Any idea what the problem is? 知道是什么问题吗?

I think you need to read more before just starting to experiment. 我认为您需要在开始实验之前阅读更多内容。 Celery is a distributed task queue, which basically means, it polls a queue to see if there is any task that needs to be run. Celery是分布式任务队列,这基本上意味着,它轮询队列以查看是否有任何需要运行的任务。 If there is, it runs the task. 如果存在,它将运行任务。

About your setup, you seem to have a task runner, but not the queue that runner requires to poll to check if there is any tasks to be run. 关于您的设置,您似乎有一个任务运行器,但没有运行器需要轮询以检查是否有任何要运行的任务的队列。 The configuration CELERY_BROKER_URL is about that queue. 配置CELERY_BROKER_URL与该队列有关。 I suggest you start by reading "Celery's Introduction documents" . 我建议您先阅读“ Celery的介绍文档” Especially "What do I need?" 特别是“我需要什么?” part. 部分。

NOTE FOR AFTER YOU FIGURE OUT THE QUEUE PART 弄清楚排队部分后的注意事项

Also, I am not sure how do you run and serve your django application, but celery requires separate processes. 另外,我不确定如何运行和服务django应用程序,但是celery需要单独的过程。 For that part you will need to skim "First Steps with Celery" . 为此,您将需要略读“ Celery的第一步”

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

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