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 | |
| parent | a55b4f84ff8fa9774b1aa3a0363d848b9a9bd252 (diff) | |
| download | cheatdb-5e44f3d64c2be1b890e393832efd9fb100adf2c0.tar.xz | |
Move Github import to backend
Fixes #41
Diffstat (limited to 'app/views')
| -rw-r--r-- | app/views/__init__.py | 2 | ||||
| -rw-r--r-- | app/views/api.py | 35 |
2 files changed, 36 insertions, 1 deletions
diff --git a/app/views/__init__.py b/app/views/__init__.py index 17b9f00..51f4908 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -30,4 +30,4 @@ def home_page(): packages = Package.query.filter_by(approved=True).all() return render_template("index.html", packages=packages) -from . import users, githublogin, packages, sass +from . import users, githublogin, packages, sass, api 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, + }) |
