0
当我加载我的页面时,我的兔子得到的消息,但从来没有消耗。当CELERY_ALWAYS_EAGER = True
时,我的任务已耗尽,但我的页面始终在等待完成任务时加载,因此在heroku上创建了一个timeout
,并且出现错误。 我在这里参加圈子。芹菜的全部目的是异步,它为什么这样做?我是否缺少一些其他配置?芹菜总是渴望跑任务vs异步
BROKER_URL=['amqp://[email protected]//','amqp://[email protected]/ysicvcrh']
BROKER_POOL_LIMIT = 1
BROKER_CONNECTION_MAX_RETRIES = None
BROKER_CONNECTION_TIMEOUT = 30
EVENT_QUEUE_EXPIRES = 60
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_ACCEPT_CONTENT = ['pickle','json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
#CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend' # AMQP is not recommended as result backend as it creates thousands of queues
CELERY_ALWAYS_EAGER = False
task.py
from __future__ import absolute_import, unicode_literals
import requests
import json
import time
import sys
import os
import random
from os import path
from celery import Celery
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from lib import myfiles
from django.db import models
from .models import mymodels
import django
django.setup()
@task(name="get_myfunction")
def get_data(user, items):
#runs a bunch of things
#saves data
#all this and page spinner on the browser tab just keeps spinning until its done
celery_settings.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', 'app.settings')
app = Celery('app', broker=['amqp://[email protected]//','amqp://hello:[email protected]/ysicvcrh'])
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
您需要运行worker来完成任务,请参阅文档http://docs.celeryproject.org/en/latest/userguide/workers.html#id1 – Jinje