Пример #1
0
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)
Пример #2
0
def task_status(task_id: str):
    task = celery.AsyncResult(task_id)

    result = {
        "task_id": task.id,
        "state": task.state,
        "result": task.result,
    }
    return result
Пример #3
0
 def get(self, task_id):
     print("task_id", task_id)
     task = celery.AsyncResult(task_id)
     return jsonify(task.result)
Пример #4
0
 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)