I am able to send the task to rabbitMQ and let my celery workers to execute the tasks but when i use the result URL with the task id, it just loads and does not show anything, I don't know if its due to connection error with Redis or what.
from flask import Flask, request
from celery import Celery
import time
app = Flask(__name__)
celery = Celery(app.name, broker='pyamqp://guest@localhost//', backend='redis://localhost:6379/0')
@celery.task
def add_numbers(a, b):
c=a+b
time.sleep(10)
return c
@app.route('/add/<a>/<b>')
def add(a,b):
c=int(a)
d=int(b)
result = add_numbers.delay(c,d)
#print("lol ",result)
return f'{result} xd Task ID: {result.task_id}'
@app.route('/result/<task_id>')
def result(task_id):
task = add_numbers.AsyncResult(task_id)
print(task.get())
if task.state == 'SUCCESS':
return f'Result: {task.get()}'
else:
return f'Task {task_id} is {task.state}'
return "no such id"
if __name__ == '__main__':
app.run(debug=True)
Try this one:-
celery = Celery(app.name, broker='pyamqp://guest@localhost//', backend='redis://redis:6379/0')