0

I am new to task queue. When i open the shell and execute the function add.delay(3,4) from the function in the shell to perform the task. I get : <AsyncResult: 30db3528-5b0f-4e74-bf47-51956a1f83e9>. How do I get a result from this function and what should i do to schedule the result to be executed 5 second later?

#celery.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

app = Celery('RedisQueue')

app.autodiscover_tasks()

`@app.task
def add(a, b):
    return a + b`

#__init__.py

from __future__ import absolute_import, unicode_literals

__all__ = ['celery_app']

#settings.py

CELERY_BROKER_URL = 'redis://localhost:6379'

CELERY_RESULT_BACKEND = 'redis://localhost:6379'

CELERY_ACCEPT_CONTENT = ['application/json']

CELERY_RESULT_SERIALIZER = 'json'

CELERY_TASK_SERIALIZER = 'json'
Curtis Banks
  • 342
  • 4
  • 20
  • Possible duplicate of [Retrieve task result by id in Celery](https://stackoverflow.com/questions/30753040/retrieve-task-result-by-id-in-celery) – Yugandhar Chaudhari Jan 21 '19 at 15:28
  • @YugandharChaudhari I am using **Redis** with Celery and the possible duplicate article is based on **RabbitMQ.** – Curtis Banks Jan 21 '19 at 15:41
  • Did you try res.get() and you can do time.sleep(5000) to pause for 5 seconds. In a thread in you don't want blocking code – Yugandhar Chaudhari Jan 21 '19 at 15:44
  • @YugandharChaudhari Yes I did try `res.get()`. For some strange reason when i use it in the shell, there is no output as if the system is waiting for some instructions. Then when i type `res.status`. the output displayed is **'PENDING'** – Curtis Banks Jan 21 '19 at 15:51
  • @YugandharChaudhari I forgot to execute `Celery -A worker -l info` in other terminal. – Curtis Banks Jan 21 '19 at 16:06

0 Answers0