diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-11 12:57:16 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-11 12:57:16 +0100 |
commit | 5e44f3d64c2be1b890e393832efd9fb100adf2c0 (patch) | |
tree | ea4a1fd0ce7fe8ed9c97687f6afd8e18b0a393e4 /app/views/api.py | |
parent | a55b4f84ff8fa9774b1aa3a0363d848b9a9bd252 (diff) | |
download | cheatdb-5e44f3d64c2be1b890e393832efd9fb100adf2c0.tar.xz |
Move Github import to backend
Fixes #41
Diffstat (limited to 'app/views/api.py')
-rw-r--r-- | app/views/api.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/views/api.py b/app/views/api.py new file mode 100644 index 0000000..277b94e --- /dev/null +++ b/app/views/api.py @@ -0,0 +1,35 @@ +from flask import * +from flask_user import * +from flask.ext import menu +from app import app +from app.models import * +from app.tasks import celery +from app.tasks.importtasks import getMeta +# from celery.result import AsyncResult + +from .utils import * + +@app.route("/tasks/getmeta/new/") +def new_getmeta_page(): + aresult = getMeta.delay(request.args.get("url")) + return jsonify({ + "poll_url": url_for("check_task", id=aresult.id), + }) + +@app.route("/tasks/<id>/") +def check_task(id): + result = celery.AsyncResult(id) + status = result.status + traceback = result.traceback + result = result.result + if isinstance(result, Exception): + return jsonify({ + 'status': status, + 'error': str(result), + # 'traceback': traceback, + }) + else: + return jsonify({ + 'status': status, + 'result': result, + }) |