def check(id): result = celery.AsyncResult(id) status = result.status traceback = result.traceback result = result.result None if isinstance(result, Exception): info = { 'id': id, 'status': status, } if current_user.is_authenticated and current_user.rank.atLeast(UserRank.ADMIN): info["error"] = str(traceback) elif str(result)[1:12] == "TaskError: ": info["error"] = str(result)[12:-1] else: info["error"] = "Unknown server error" else: info = { 'id': id, 'status': status, 'result': result, } if shouldReturnJson(): return jsonify(info) else: r = request.args.get("r") if r is not None and status == "SUCCESS": return redirect(r) else: return render_template("tasks/view.html", info=info)
def task_status(task_id: str): task = celery.AsyncResult(task_id) result = { "task_id": task.id, "state": task.state, "result": task.result, } return result
def get(self, task_id): print("task_id", task_id) task = celery.AsyncResult(task_id) return jsonify(task.result)
def run(self, celery_queue): while True: celery_event = celery_queue.get() if celery_event["type"] == "task-succeeded": task = celery.AsyncResult(celery_event["uuid"]) print(task.result)