-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-rs.py
49 lines (38 loc) · 1.31 KB
/
app-rs.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
40
41
42
43
44
45
46
47
48
49
import os
import traceback as ex
from dotenv import load_dotenv
from flask import Flask, request
import jager.groupsig as groupsig
import jager.jobs as jobs
import jager.config as config
import jager.response as response
load_dotenv()
class TracebackProvider:
def create_instance_path(self, app):
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
def start(self, test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(SECRET_KEY=config.APP_SECRET_KEY)
self.create_instance_path(app)
gpk = groupsig.get_gpk()
@app.post('/submit')
def submit():
jobs.submit(request=request, gpk=gpk)
return response.ok()
@app.post('/traceback')
def traceback():
cts = jobs.traceback(request=request, gpk=gpk)
return response.ok({'res': cts})
@app.errorhandler(404)
def page_not_found(e):
return response.not_found()
@app.errorhandler(Exception)
def handle_all_exceptions(e):
return response.handle_ex(e)
return app
def create_app(test_config=None):
return TracebackProvider().start(test_config)