diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-11 15:04:17 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-11 15:04:17 +0100 |
commit | 92717f31dd94ad1c763641a397305de9bc143df9 (patch) | |
tree | 3ff4f1fbfbd0f2b1490c46905b959e75dacbaafa /app/views/tasks.py | |
parent | 5424f0aa3499ef9cad33ebad4db055860b8000c8 (diff) | |
download | cheatdb-92717f31dd94ad1c763641a397305de9bc143df9.tar.xz |
Add VCS import from Github
Diffstat (limited to 'app/views/tasks.py')
-rw-r--r-- | app/views/tasks.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/views/tasks.py b/app/views/tasks.py new file mode 100644 index 0000000..b82c326 --- /dev/null +++ b/app/views/tasks.py @@ -0,0 +1,50 @@ +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 .utils import shouldReturnJson +# 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 + + info = None + if isinstance(result, Exception): + info = { + 'status': status, + 'error': str(result), + } + else: + info = { + 'status': status, + 'result': result, + } + + if shouldReturnJson(): + return jsonify(info) + else: + r = request.args.get("r") + if r is None: + abort(422) + + if status == "SUCCESS": + flash("Task complete!", "success") + return redirect(r) + else: + return render_template("tasks/view.html", info=info) |