-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathapp.py
32 lines (23 loc) · 836 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import celery.states as states
from flask import Flask, Response
from flask import url_for, jsonify
from worker import celery
dev_mode = True
app = Flask(__name__)
@app.route('/add/<int:param1>/<int:param2>')
def add(param1: int, param2: int) -> str:
task = celery.send_task('tasks.add', args=[param1, param2], kwargs={})
response = f"<a href='{url_for('check_task', task_id=task.id, external=True)}'>check status of {task.id} </a>"
return response
@app.route('/check/<string:task_id>')
def check_task(task_id: str) -> str:
res = celery.AsyncResult(task_id)
if res.state == states.PENDING:
return res.state
else:
return str(res.result)
@app.route('/health_check')
def health_check() -> Response:
return jsonify("OK")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)