@celery.task(bind=True)
def counter(self):
for i in xrange(100):
time.sleep(1)
self.update(state='PROGRESS', meta={'current': i})
return {'status': 'complete'}
你有这样的烧瓶路线:
^{pr2}$
最后,您的任务状态路径如下所示:
from celery.result import AsyncResult
...
@app.route('/status/<task_id>/')
def status(task_id):
task = AsyncResult(task_id) # retrieving the task we started
if task.state == 'PROGRESS':
response = {
'state': task.state,
'current': task.info.get('current', 0)
}
return jsonify(response)
我们假设你有这样一个任务:
你有这样的烧瓶路线:
^{pr2}$最后,您的任务状态路径如下所示:
相关问题 更多 >
编程相关推荐