当我CELERY_ALWAYS_EAGER=False
加载我的页面时,我的兔子会收到消息,但从不消耗。当CELERY_ALWAYS_EAGER = True
时,我的任务被消耗,但我的页面总是在等待完成任务时加载,因此在heroku上创建timeout
并给出错误。
我在这里转圈。芹菜的整个目的是异步,它为什么这样做?我错过了其他一些配置吗?
BROKER_URL=['amqp://guest@localhost//','amqp://aughhhhhhtears@mosquito.rmq.cloudamqp.com/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://guest@localhost//','amqp://hello:world@mosquito.rmq.cloudamqp.com/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))
答案 0 :(得分:0)
我在另一个董事会上问了一个人。事实证明我没有打开heroku的dynos