python - Setting up a result backend (rpc) with Celery in Django -
i attempting result backend working on local machine project i'm working on running issue.
currently trying create queue system in order lab create cases. prevent duplicate sequence numbers being used. using celery our printing figured create new celery queue , use handle case. front-end needs results of case creations display case number created.
http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#rabbitmq
i following above tutorial on getting celery configured. below source:
celeryconfig.py:
from kombu import queue celery_default_queue = 'celery' celery_default_exchange = 'celery' celery_default_exchange_type = 'direct' celery_result_backend = 'rpc://' celery_result_persistent = false celery_queues = ( queue('celery', routing_key="celery"), queue('case_creation', routing_key='create.#') ) celery_routes = { 'case.tasks.create_case': { 'queue': 'case_creation', 'routing_key': 'create.1' }, 'print.tasks.connect_and_serve': { 'queue': 'celery', 'routing_key': 'celery' } }
celery.py:
import os celery import celery django.conf import settings os.environ.setdefault('django_settings_module', 'proj.settings.local') app = celery('proj', broker='amqp://guest@localhost//') app.config_from_object('proj.celeryconfig') app.autodiscover_tasks(lambda: settings.installed_apps)
tasks.py:
import celery django.db import integrityerror case.case_create import casecreate @celery.task(bind=true) def create_case(self, data, user, ip): try: acc = casecreate(data, user, ip) return acc.begin() except integrityerror e: self.retry(exc=e, countdown=2)
here view calls above task:
@require_authentication() @requires_api_signature() @csrf_exempt @require_http_methods(['post']) def api_create_case(request): result = create_case.delay(json.loads(request.body.decode('utf-8')), request.user, get_ip_address(request)) print(str(result)) # prints task id print(str(result.get(timeout=1))) # throws error return httpresponse(json.dumps({'result': str(result)}), status=200)
i start celery queue following command:
celery -a proj worker -q case_creation -n case_worker -c 1
when run celery worker see results show under config:
-------------- celery@case_worker v3.1.16 (cipater) ---- **** ----- --- * *** * -- windows-8-6.2.9200 -- * - **** --- - ** ---------- [config] - ** ---------- .> app: proj:0x32a2990 - ** ---------- .> transport: amqp://guest:**@localhost:5672// - ** ---------- .> results: rpc:// - *** --- * --- .> concurrency: 1 (prefork) -- ******* ---- --- ***** ----- [queues] -------------- .> case_creation exchange=celery(direct) key=create.#
when run program , submit new case error message get:
no result backend configured. please see documentation more information.
i have attempted every single thing can find online. there out there can point me in right direction? i'm close , tired of looking @ code.
if want keep result, try keeping results
app = celery('proj', backend='amqp', broker='amqp://guest@localhost//')
edit
make sure client configured right backend.
if reason client configured use different backend worker, not able receive result, make sure backend correct inspecting it:
try see output:
>>> result = task.delay(…) >>> print(result.backend)
other solutions instead of
app = celery('proj', backend='amqp', broker='amqp://', include=['proj.tasks'])
try:
app = celery('proj', broker='amqp://', include=['proj.tasks']) app.conf.update( celery_result_backend='amqp' )
Comments
Post a Comment