|
|
@@ -1,4 +1,7 @@
|
|
|
+from hashlib import new
|
|
|
+import random
|
|
|
import uuid, json, logging
|
|
|
+from config import MYSQL_URI
|
|
|
# from service.video.Video3DAnalyzer import Video3DAnalyzer
|
|
|
from db import db
|
|
|
from flask import request
|
|
|
@@ -7,45 +10,66 @@ from worker.thread_pool import pool
|
|
|
from route.util import make_response
|
|
|
from flask import Blueprint
|
|
|
from service.photo.StandingPhotoAnalyzer import StandingPhotoAnalyzer
|
|
|
+from sqlalchemy import create_engine
|
|
|
|
|
|
-bp = Blueprint("analyze", __name__, url_prefix='/')
|
|
|
|
|
|
+bp = Blueprint("analyze", __name__, url_prefix='/')
|
|
|
|
|
|
def callback_generator(task_uuid):
|
|
|
def callback(status, **args):
|
|
|
try:
|
|
|
- # you can now use some_session to run multiple queries, etc.
|
|
|
- # remember to close it when you're finished!
|
|
|
+ # 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)
|
|
|
+ # from sqlalchemy.orm import scoped_session
|
|
|
+ # from sqlalchemy.orm import sessionmaker
|
|
|
+
|
|
|
+
|
|
|
+ # engine = create_engine(
|
|
|
+ # url=MYSQL_URI,
|
|
|
+ # pool_size=5, # default in SQLAlchemy
|
|
|
+ # max_overflow=10, # default in SQLAlchemy
|
|
|
+ # pool_timeout=1, # raise an error faster than default
|
|
|
+ # )
|
|
|
+
|
|
|
+ # session_factory = sessionmaker(bind=engine)
|
|
|
+ # # Session = scoped_session(session_factory)
|
|
|
+
|
|
|
+ # # now all calls to Session() will create a thread-local session
|
|
|
+ # some_session = session_factory()
|
|
|
+ # logging.error("calling back" + status)
|
|
|
+ # logging.error("get" + task_uuid)
|
|
|
+
|
|
|
+
|
|
|
+ # new_task = Task(str(random.randint(0, 100000000)), "PHOTO_STANDINGPOSE", status=status)
|
|
|
+ # some_session.add(new_task)
|
|
|
+ # some_session.commit()
|
|
|
+ # print("fk")
|
|
|
+
|
|
|
+
|
|
|
+ # task = some_session.query(Task).get(task_uuid)
|
|
|
+ task = Task.query.get(task_uuid)
|
|
|
+
|
|
|
+ logging.error(task.status)
|
|
|
task.status = status
|
|
|
if status == 'FINISHED':
|
|
|
task.result = json.dumps(args['result'])
|
|
|
-
|
|
|
- some_session.commit()
|
|
|
- print("commited")
|
|
|
+
|
|
|
+ db.session.commit()
|
|
|
+ # some_session.commit()
|
|
|
+ logging.error("commited")
|
|
|
except Exception as e:
|
|
|
logging.exception("nmsl", exc_info=e)
|
|
|
|
|
|
return callback
|
|
|
|
|
|
|
|
|
+
|
|
|
@bp.route("photos/analysis", methods=['POST'])
|
|
|
def photo_analysis():
|
|
|
req = request.get_json()
|
|
|
-
|
|
|
+
|
|
|
ana = StandingPhotoAnalyzer(req['front'], req['right'], req['height'])
|
|
|
|
|
|
task_uuid = str(uuid.uuid4())
|
|
|
@@ -57,13 +81,12 @@ def photo_analysis():
|
|
|
|
|
|
pool.submit(ana.analyze, callback_generator(task_uuid))
|
|
|
|
|
|
- return make_response(201, "success", {'task_uuid': task_uuid})
|
|
|
-
|
|
|
+ return make_response(201, "success", {'task_uuid' : task_uuid})
|
|
|
|
|
|
@bp.route("videos/analysis", methods=['POST'])
|
|
|
def video_analysis():
|
|
|
req = request.get_json()
|
|
|
-
|
|
|
+
|
|
|
# ana_3d = Video3DAnalyzer()
|
|
|
|
|
|
task_uuid = str(uuid.uuid4())
|