芹菜任务未由芹菜处理



总计芹菜和django菜鸟在这里,如果问题很微不足道,对不起。基本上是问题是, @app.task定义的任何功能都没有被芹菜处理,它正常运行,好像芹菜不存在。

我的celery_app.py文件是 -

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery(broker=settings.CELERY_BROKER_URL)
app.config_from_object('django.conf:settings')
app.autodiscover_tasks()
if __name__ == '__main__':
    app.start()

我的tasks.py文件是 -

from project.celery_app import app
@app.task
def mytask():
    ...

我在终端中运行芹菜时获得以下输出 -

 -------------- celery@LAPTOP v4.1.0 (latentcall)
---- **** -----
--- * ***  * -- Windows-10-10.0.16299-SP0 2017-12-20 19:27:24
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app:         __main__:0x229ce2884e0
- ** ---------- .> transport:   amqp://user:**@localhost:5672/myvhost
- ** ---------- .> results:     disabled://
- *** --- * --- .> concurrency: 8 (solo)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this         worker)
--- ***** -----
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery

[tasks]
  . account.tasks.mytask
[2017-12-20 19:27:24,085: INFO/MainProcess] Connected to     amqp://user:**@127.0.0.1:5672/myvhost
[2017-12-20 19:27:24,101: INFO/MainProcess] mingle: searching for neighbors
[2017-12-20 19:27:25,126: INFO/MainProcess] mingle: all alone
[2017-12-20 19:27:25,141: WARNING/MainProcess]     c:programdataanaconda2envsmyenvlibsite-    packagesceleryfixupsdjango.py:202: UserWarning: Using settings.DEBUG leads to     a memory leak, never use this setting in production environments!
  warnings.warn('Using settings.DEBUG leads to a memory leak, never '
[2017-12-20 19:27:25,141: INFO/MainProcess] celery@LAPTOP- ready.

因此,我的任务是芹菜所知道的,但对此无能为力。该任务在按钮点击时运行,使用-loglevel =调试,可以看到芹菜不受其影响。我正在使用RabbitMQ作为经纪人,芹菜4.1.0,Python3和Django-1.10.5。任何帮助将不胜感激!

正如我想的那样,这是一个简单的错误。只需要将mytask()更改为mytask.delay(),芹菜开始接收它。

.delay()实际上是一种shorcut方法。如果要提供其他选项,则必须使用.apply_async()

可以在此处找到官方文档:http://docs.celeryproject.org/en/latest/userguide/calling.html

相关内容

  • 没有找到相关文章

最新更新