python - Celery 任务不起作用

标签 python django celery

Celery 文档说 Celery 3.1 可以开箱即用地与 django 一起使用。但任务不起作用。我有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'),
)

项目/celery.py 从 future 导入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 -A 项目工作人员 --loglevel=INFO

但什么也没发生。

最佳答案

您应该使用 celerybeat 来运行周期性任务。

celery -A project worker --loglevel=INFO

启动工作程序,它执行实际工作。

celery -A proj beat

启动beat服务,要求工作完成工作。

关于python - Celery 任务不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34875099/

相关文章:

python - 将 sklearn LogisticRegression 系数链接到稀疏矩阵中的项,并获得统计显着性/C.I

python - 我如何使用 "leaky_relu"作为 Tensorflow "tf.layers.dense"中的激活?

ajax - Django:ajax 和请求

rabbitmq - Celery在RabbitMQ消息队列中创建3个队列

python - 来自响应对象的文本是否不能很好地使用正则表达式?

python - Django 缺少 Vary :Cookie header for cached views

python - 如何在 Django 中正确设置多个项目的环境设置?

python - 使用 Django 的 Python 脚本中的明显内存泄漏

python - 强制 Celery 使用 Python 3

python - 使用 Flask 和 SQLAlchemy 的 Celery 任务中的数据库未更新