芹菜不在django中工作,只是等待(待定)

时间:2019-07-10 08:12:33

标签: django celery

我正在尝试找到芹菜的工作方式。我有一个约有10个应用程序的项目。现在我要使用celery。

setting.py:

Threshold

我在Rabbitmq中使用以下信息创建了一个用户:/* animation speed */ .container { -webkit-animation: rotate 18s infinite linear; animation: rotate 18s infinite linear; } /* native */ .cube { transform:scaleX(.7) scaleY(.7); } * { margin:0; padding:0; outline:none; box-sizing: border-box; } .stage { width:240px; height:360px; overflow:hidden; } .cube { width:240px; height:400px; margin-top:-20px; -ms-perspective:1000px; -webkit-perspective: 1000px; perspective: 1000px; -ms-perspective-origin: center center; -webkit-perspective-origin: center center; perspective-origin: center center; } .container { display:block; width: 240px; height: 400px; -ms-transform-style: preserve-3d; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; } .side { display:block; position: absolute; width: 240px; height: 400px; background-position:center center; background-repeat:no-repeat; background-size:cover; } .face1 { -webkit-transform: translateZ(120px); transform: translateZ(120px); background-color: green; } .face2 { -webkit-transform: translateX(120px) rotateY(90deg); transform: translateX(120px) rotateY(90deg); background-color: red; } .face3 { -webkit-transform: translateZ(-120px) scale(-1, 1); transform: translateZ(-120px) scale(-1, 1); background-color: teal; } .face4 { -webkit-transform: translateX(-120px) rotateY(90deg) scale(-1, 1); transform: translateX(-120px) rotateY(90deg) scale(-1, 1); background-color: black; } @-webkit-keyframes rotate { 100% { -webkit-transform: rotateY(-360deg); transform: rotateY(-360deg); } } @keyframes rotate { 100% { -webkit-transform: rotateY(-360deg); transform: rotateY(-360deg); } } </style> </head> <body cz-shortcut-listen="true"> <div class="stage"> <div class="cube"> <a class="container" href=""> <span class="face1 side"></span> <span class="face2 side"></span> <span class="face3 side"></span> <span class="face4 side"></span> </a> </div> </div> </body></html> CELERY_BROKER_URL = 'amqp://rabbitmq:rabbitmq@localhost:5672/rabbitmq_vhost' CELERY_RESULT_BACKEND = 'redis://localhost' 。然后我创建一个名称为username: rabbitq的虚拟主机,并为其添加password:rabbitmq权限。我认为一切都很好,因为关于rabbitmq的所有错误都消失了。

这是我的test.py:

rabbitmq_vhost

task.py:

rabbitmq

celery.py:

from .task import when_task_expiration

def test_celery():
    result = when_task_expiration.apply_async((2, 2), countdown=3)
    print(result.get())

现在,当我在python shell中调用from __future__ import absolute_import, unicode_literals import logging from celery import shared_task from proj.celery import app @app.task def when_task_expiration(task, x): print(task.id, 'task done') return True 时,它处于挂起状态。我尝试替换from __future__ import absolute_import, unicode_literals import os from celery import Celery # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') app = Celery('proj') # Using a string here means the worker doesn't have to serialize # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys # should have a `CELERY_` prefix. app.config_from_object('django.conf:settings', namespace='CELERY') # Load task modules from all registered Django app configs. app.autodiscover_tasks() test_celery()但注意已更改。即使我尝试使用@shared_task代替{{1 }},再也没有任何反应。

我正试图在过去this queation的特定时间内使用celery来调用函数。谢谢。

1 个答案:

答案 0 :(得分:2)

您很可能忘记运行至少一个Celery worker进程。为此,请在外壳程序中执行以下操作:celery worker -A proj.celery -c 4 -l DEBUG(此处我假设您的Celery应用程序已在proj / celery.py中定义,因为其中有Celery('proj')