芹菜任务不起作用

芹菜任务不起作用

本文介绍了芹菜任务不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Celery文档说Celery 3.1可以直接使用django.但是任务不起作用.我有task.py:

Celery docs say that Celery 3.1 can work with django out of box. But tasks not working. I have tasks.py:

from celery import task
from datetime import timedelta

@task.periodic_task(run_every=timedelta(seconds=20), ignore_result=True)
    def disable_not_confirmed_users():
        print "start"

配置:

from kombu import Exchange, Queue

CELERY_SEND_TASK_ERROR_EMAILS = True
BROKER_URL = 'amqp://guest@localhost//'
CELERY_DEFAULT_QUEUE = 'project-queue'
CELERY_DEFAULT_EXCHANGE = 'project-queue'
CELERY_DEFAULT_ROUTING_KEY = 'project-queue'
CELERY_QUEUES = (
    Queue('project-queue', Exchange('project-queue'), routing_key='project-queue'),
)

project/celery.py从未来导入absolute_import

project/celery.py from future import absolute_import

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')

from django.conf import settings


app = Celery('project')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

运行celery: celery-项目工作人员--loglevel = INFO

但是什么也没发生.

推荐答案

您应该使用celery beat来执行定期任务.

you should use celery beat to run periodic task.

celery -A project worker --loglevel=INFO

启动工作程序,该工作程序实际上会工作.

starts the worker, which does the actually work.

celery -A proj beat

启动节拍服务,要求工作完成这项工作.

starts the beat service, which asks the work to do the job.

这篇关于芹菜任务不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:34