Wenn CELERY_ALWAYS_EAGER=False
ich meine Seite laden, bekommt mein Kaninchen die Nachricht, aber nie verbraucht. Wenn CELERY_ALWAYS_EAGER = True
, meine Aufgabe verbraucht wird, aber meine Seite wird immer geladen, wie es wartet, um die Aufgabe zu beenden, wodurch eine timeout
auf Heroku erstellt wird, und gibt einen Fehler. Ich gehe hier im Kreis. Der ganze Zweck von Sellerie ist async, warum tut es das? Fehle ich eine andere Konfiguration? Sellerie immer eifrig läuft Aufgabe 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))
U muss den Arbeiter ausführen, um die Aufgabe zu übernehmen, siehe Dokument http://docs.selleryproject.org/en/latest/userguide/workers.html#id1 – Jinje