forked from ml-lab/DeepVideoAnalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_flask.py
More file actions
executable file
·45 lines (36 loc) · 1.38 KB
/
run_flask.py
File metadata and controls
executable file
·45 lines (36 loc) · 1.38 KB
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
#!/usr/bin/env python
import django
import sys, os, logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='../logs/flask.log',
filemode='a')
sys.path.append(os.path.join(os.path.dirname(__file__),'../'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dva.settings")
django.setup()
from dvaapp.models import TEvent
from django.conf import settings
from dvaapp.task_handlers import handle_perform_analysis, handle_perform_indexing, handle_perform_detection
from flask import Flask
app = Flask(__name__)
@app.route('/<pk>/')
def process_task(pk):
start = TEvent.objects.get(pk=pk)
logging.info("Executing {} {}".format(start.operation,pk))
if start.operation == 'perform_indexing':
handle_perform_indexing(start)
elif start.operation == 'perform_detection':
handle_perform_detection(start)
elif start.operation == 'perform_analysis':
handle_perform_analysis(start)
else:
raise ValueError("Unknown task name {}".format(start.operation))
return "Done"
@app.route('/')
def ready():
return "running"
if __name__ == '__main__':
with open('flask.pid','w') as pidfile:
pidfile.write(str(os.getpid()))
app.run(port=settings.GLOBAL_MODEL_FLASK_SERVER_PORT,debug=False)