Browse Source

修改sagemaker取消异步

zhangdongming 1 year ago
parent
commit
5f5564734b
1 changed files with 24 additions and 13 deletions
  1. 24 13
      Controller/AiController.py

+ 24 - 13
Controller/AiController.py

@@ -128,6 +128,30 @@ class AiView(View):
                 if (now_time - add_time) <= (3600 * 24 * 3):
                 if (now_time - add_time) <= (3600 * 24 * 3):
                     ai_server = 'rekognition'
                     ai_server = 'rekognition'
 
 
+            redis_obj = RedisObject(db=6)
+            APP_NOTIFY_KEY = f'ASJ:NOTIFY:PUSH:{uid}:{channel}'  # 推送间隔缓存KEY
+            push_cache_data = redis_obj.get_data(APP_NOTIFY_KEY)
+            is_push = False if push_cache_data else True
+
+            notify_data = uid_push_qs[0]['uid_set__msg_notify']
+
+            # APP推送提醒状态
+            notify = self.is_ai_push(uid, notify_data) if is_push else is_push
+
+            if ai_server == 'sageMaker':  # 自建模型sageMaker AI
+                sage_maker = SageMakerAiObject()
+                ai_result = sage_maker.sage_maker_ai_server(uid, file_list)  # 图片base64识别AI标签
+                if ai_result:
+                    res = sage_maker.get_table_name(uid, ai_result, detect_group)
+                    if not res:  # 当前识别结果未匹配
+                        return response.json(0)
+                    # 保存推送消息
+                    sage_maker.save_push_message(uid, n_time, uid_push_qs, channel, res, file_list, notify)
+                    self.add_push_cache(APP_NOTIFY_KEY, redis_obj, push_cache_data,
+                                        uid_push_qs[0]['uid_set__new_detect_interval'])
+                    return response.json(0)
+                TIME_LOGGER.info(f'uid={uid},sagemakerAI识别失败')
+
             push_thread = threading.Thread(target=self.image_label_detection,
             push_thread = threading.Thread(target=self.image_label_detection,
                                            kwargs={'ai_server': ai_server, 'uid': uid, 'file_list': file_list,
                                            kwargs={'ai_server': ai_server, 'uid': uid, 'file_list': file_list,
                                                    'detect_group': detect_group, 'n_time': n_time,
                                                    'detect_group': detect_group, 'n_time': n_time,
@@ -184,19 +208,6 @@ class AiView(View):
             # APP推送提醒状态
             # APP推送提醒状态
             notify = self.is_ai_push(uid, notify_data) if is_push else is_push
             notify = self.is_ai_push(uid, notify_data) if is_push else is_push
 
 
-            if ai_server == 'sageMaker':  # 自建模型sageMaker AI
-                sage_maker = SageMakerAiObject()
-                ai_result = sage_maker.sage_maker_ai_server(uid, file_list)  # 图片base64识别AI标签
-                if ai_result:
-                    res = sage_maker.get_table_name(uid, ai_result, detect_group)
-                    if not res:  # 当前识别结果未匹配
-                        return False
-                    # 保存推送消息
-                    sage_maker.save_push_message(uid, n_time, uid_push_qs, channel, res, file_list, notify)
-                    self.add_push_cache(APP_NOTIFY_KEY, redis_obj, push_cache_data,
-                                        uid_push_qs[0]['uid_set__new_detect_interval'])
-                    return True
-
             TIME_LOGGER.info(f'*****现执行Reko,uid={uid}识别类型={ai_server}')
             TIME_LOGGER.info(f'*****现执行Reko,uid={uid}识别类型={ai_server}')
             dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
             dir_path = os.path.join(BASE_DIR, 'static/ai/' + uid + '/' + str(n_time))
             if not os.path.exists(dir_path):
             if not os.path.exists(dir_path):