In the project, I try to poll task.state a long-running task and update its execution status. He worked in development, but it will not work when I transfer the project to the production server. I continued to receive "PENDING" even if I see that the task began on a flower. However, I can still get results updated after completing the task when task.state == 'SUCCESS'. I use python 2.6, Django 1.6, and Celery 3.1 in production, resulting in AMQP.
@csrf_exempt def poll_state(request): data = 'Fail' if request.is_ajax(): if 'task_id' in request.POST.keys() and request.POST['task_id']: task_id = request.POST['task_id'] email = request.POST['email'] task = AsyncResult(task_id) print "task.state=", task.state if task.state == 'STARTED': task_state = 'Running' data = 'Running' #data = 'Running' elif task.state == 'PENDING' or task.state == 'RETRY': task_state = 'Waiting' data = 'Pending' elif task.state == 'SUCCESS': task_state = 'Finished' if task.result: data = task.result else: data = 'None' else: task_state = task.state data = 'Error' print 'data status =', task_state else: task_state = task.state data = 'Error' else: task_state = task.state data = "Error" json_data = json.dumps({'task_state':task_state, 'task_data':data}) return HttpResponse(json_data, mimetype='application/json')
on a different note, the flower always shows the status of workers offline, but the task status is correct. When using the events of celery 3.1.12 (Cipater), it shows the correct status of the employee.
source share