簡體   English   中英

"我的自定義 django-admin 命令不會調用 celery 任務"

[英]My custom django-admin command won't call celery task

我正在嘗試編寫一個執行 celery 任務的自定義 django-admin 命令,但是該任務沒有執行,並且當我嘗試時 django 只是掛起。

from django.core.management.base import BaseCommand
from myapp.tasks import my_celery_task

class Command(BaseCommand):
    def handle(self, *args, **options):
        print "starting task"
        my_celery_task.delay()
        print "task has been sent"

調用命令時我收到的輸出是:

starting task

我從來沒有到達“任務已發送”這一行。 它只是掛起。 我不確定為什么任務沒有運行。 當被視圖調用時,芹菜任務被完美地調用。

升級到High Sierra后,Mac上的RabbitMQ實際上是問題。

這似乎適用於 celery 5.1.2,但如果它是shared_task<\/code>則不行

======任務.py

from celery import current_app
from celery.schedules import crontab
app = current_app._get_current_object()

@app.task
def my_celery_task():
    # Do something interesting
    return 0 # Return the result of this operation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM