2017-10-11 8 views
0

Quand CELERY_ALWAYS_EAGER=False Je peux charger ma page, mon lapin reçoit le message mais ne le consomme jamais. Lorsque CELERY_ALWAYS_EAGER = True, ma tâche est consommée mais ma page est toujours en cours de chargement car il attend pour terminer la tâche, créant ainsi un timeout sur heroku, et donne une erreur. Je vais en rond ici. Tout le but du céleri est d'async, pourquoi fait-il cela? Ai-je manqué une autre configuration?Céleri toujours désireux de courir tâche vs async

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

U besoin de lancer le travailleur pour prendre la tâche, se référer au document http://docs.celeryproject.org/en/latest/userguide/workers.html#id1 – Jinje

Répondre

0

J'ai demandé quelqu'un à un autre conseil. Il s'avère que je n'ai pas allumé les dynos d'heroku