-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (30 loc) · 1.14 KB
/
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
33
34
35
36
37
38
39
from flask import Flask, make_response
from app.service import services as ss
from flask import request
import threading
from flask import jsonify
app = Flask(__name__)
@app.route('/noop',methods = ['GET'])
def noop():
return make_response(ss.noop(), 204)
@app.route('/jobs', methods = ['POST'])
def notify():
# in case request comes with json body
body = request.get_json()
# in case request body is required, use this
# if body == None:
# return make_response('Bad request', 400)
job_id = ss.create_job_id()
# create a folder for this job id. It returns true if the creation was successful
if ss.create_job(job_id):
ss.create_status(job_id, "202", False, 'Accepted', body)
# start up a thread for this action and return the jobid to the requester
action = threading.Thread(target=ss.do, args=(None, job_id))
action.start()
return jsonify(ss.get_status(job_id))
@app.route('/jobs/<job_id>', methods = ['GET'])
def check_status(job_id):
return jsonify(ss.get_status(job_id))
app_port = 5000
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=app_port)