|
|
@@ -1,4 +1,4 @@
|
|
|
-import uuid, json
|
|
|
+import uuid, json, logging
|
|
|
# from service.video.Video3DAnalyzer import Video3DAnalyzer
|
|
|
from db import db
|
|
|
from flask import request
|
|
|
@@ -13,14 +13,34 @@ bp = Blueprint("analyze", __name__, url_prefix='/')
|
|
|
|
|
|
def callback_generator(task_uuid):
|
|
|
def callback(status, **args):
|
|
|
- print("caling back")
|
|
|
- task = Task.query.get(task_uuid)
|
|
|
- task.status = status
|
|
|
- if status == 'FINISHED':
|
|
|
- task.result = json.dumps(args['result'])
|
|
|
+
|
|
|
|
|
|
- db.session.add(task)
|
|
|
- db.session.commit()
|
|
|
+
|
|
|
+ try:
|
|
|
+ # you can now use some_session to run multiple queries, etc.
|
|
|
+ # remember to close it when you're finished!
|
|
|
+ from app import app
|
|
|
+ with app.app_context():
|
|
|
+ from sqlalchemy.orm import scoped_session
|
|
|
+ from sqlalchemy.orm import sessionmaker
|
|
|
+
|
|
|
+ session_factory = sessionmaker(bind=db.engine)
|
|
|
+ Session = scoped_session(session_factory)
|
|
|
+
|
|
|
+ # now all calls to Session() will create a thread-local session
|
|
|
+ some_session = Session()
|
|
|
+ print("calling back" + status)
|
|
|
+ print("get" + task_uuid)
|
|
|
+ task = some_session.query(Task).get(task_uuid)
|
|
|
+ print(task.status)
|
|
|
+ task.status = status
|
|
|
+ if status == 'FINISHED':
|
|
|
+ task.result = json.dumps(args['result'])
|
|
|
+
|
|
|
+ some_session.commit()
|
|
|
+ print("commited")
|
|
|
+ except Exception as e:
|
|
|
+ logging.exception("nmsl", exc_info=e)
|
|
|
|
|
|
return callback
|
|
|
|
|
|
@@ -37,9 +57,9 @@ def photo_analysis():
|
|
|
db.session.add(new_task)
|
|
|
db.session.commit()
|
|
|
|
|
|
- ana.analyze(callback_generator(task_uuid))
|
|
|
+ # ana.analyze(callback_generator(task_uuid))
|
|
|
|
|
|
- # pool.submit(ana.analyze, (callback_generator(task_uuid), ))
|
|
|
+ pool.submit(ana.analyze, callback_generator(task_uuid))
|
|
|
|
|
|
return make_response(201, "success", {'task_uuid' : task_uuid})
|
|
|
|