python - Query task state - Celery & redis -
okay have relatively simple problem think, , it's i'm hitting brick wall it. have flask app, , webpage allows run number of scripts on server side using celery & redis(broker).
all want do, when start task give name/id (task portrayed button on client side) i.e.
@app.route('/start_upgrade/<task_name>') def start_upgrade(task_name): example_task.delay(1, 2, task_name=task_name) then after task has kicked off want see if task running/waiting/finished in seperate request, preferably like;
@app.route('/check_upgrade_status/<task_name>') def get_task_status(task_name): task = celery.get_task_by_name(task_name) task_state = task.state return task_state # pseudocode but can't find in docs. new celery though fyi assume know nothing. obvious, need able query task state python, no cli commands please.
any alternative methods of achieving goal of querying queue welcome.
when start task delay or apply_async object asyncresultis created , contains id of task. have store in variable.
for example
@app.route('/start_upgrade/<task_name>') def start_upgrade(task_name): res = example_task.delay(1, 2, task_name=task_name) print res.id you can store id , maybe associate else in database (or print did in example).
then can check status of task in python console :
from celery.result import asyncresult asyncresult(your_task_id).status take @ result documentation should need there : http://docs.celeryproject.org/en/latest/reference/celery.result.html
Comments
Post a Comment