2017-10-11 40 views
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)) 
+0

您需要運行worker來完成任務,請參閱文檔http://docs.celeryproject.org/en/latest/userguide/workers.html#id1 – Jinje

回答

0

我問另一個人董事會。事實證明,我沒有打開heroku的dynos