liyuyi@c-top.com.cn 4 anni fa
parent
commit
68cdfdafb6
1 ha cambiato i file con 27 aggiunte e 25 eliminazioni
  1. 27 25
      ai_time_task_creative_handler.py

+ 27 - 25
ai_time_task_creative_handler.py

@@ -9,8 +9,8 @@ from concurrent_log import ConcurrentTimedRotatingFileHandler
 from utils.ConstantConfig import *
 from utils.DataBaseConfig import *
 from utils.CommonFunction import get_history_video_info, get_new_video_info, get_missing_video_info, \
-                                 get_top_video_info, get_campaign_and_group_name_rule, get_app_detail, get_request_data,\
-                                 refresh_video, get_app_list
+    get_top_video_info, get_campaign_and_group_name_rule, get_app_detail, get_request_data, \
+    refresh_video, get_app_list
 
 from ai_strategy_request_func import ai_strategy_request_parse
 
@@ -28,6 +28,7 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
     """
     补充历史遗漏素材(关联创意个数为0个素材)
     """
+
     def post(self):
         data = self.request.body
         data = str(data, 'utf8')
@@ -154,8 +155,8 @@ class AiHistoricalMissingMaterial(tornado.web.RequestHandler):
                         self.write(json.dumps(request))
                         self.flush()
         except Exception:
-            logger.error(traceback.format_exc())
-            self.write(json.dumps(traceback.format_exc()))
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
+            self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
             self.flush()
 
 
@@ -163,6 +164,7 @@ class AiAutoCreative(tornado.web.RequestHandler):
     """
     每5分钟,检查一次是否有上新素材,有的话,就自动创建
     """
+
     def post(self):
         data = self.request.body
         data = str(data, 'utf8')
@@ -292,7 +294,7 @@ class AiAutoCreative(tornado.web.RequestHandler):
                         logger.info("account_id = %s, 素材自动上新 没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"
                                     % account_id)
                         self.write(json.dumps({"account_id": account_id,
-                                              "message": "素材自动上新 没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
+                                               "message": "素材自动上新 没有获取到广告计划命名规则 或 广告组命名规则,不发送ai策略请求!"}))
                         self.flush()
                     else:
                         request_data = get_request_data(account_id=account_id,
@@ -307,8 +309,8 @@ class AiAutoCreative(tornado.web.RequestHandler):
                         self.write(json.dumps(request))
                         self.flush()
         except Exception:
-            logger.error(traceback.format_exc())
-            self.write(json.dumps(traceback.format_exc()))
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
+            self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
             self.flush()
 
 
@@ -316,6 +318,7 @@ class AiHighQualityMaterial(tornado.web.RequestHandler):
     """
     补充历史高质量素材  -- 测试通过 在AD后台创建成功,检查AD信息和数据库表 没有问题
     """
+
     def post(self):
         data = self.request.body
         data = str(data, 'utf8')
@@ -452,8 +455,8 @@ class AiHighQualityMaterial(tornado.web.RequestHandler):
                         self.write(json.dumps(request))
                         self.flush()
         except Exception:
-            logger.error(traceback.format_exc())
-            self.write(json.dumps(traceback.format_exc()))
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
+            self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
             self.flush()
 
 
@@ -461,6 +464,7 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
     """
     每天22:00 调用该任务,检查当天创意是否创建达到上限,否则使用历史高质量素材填满
     """
+
     def post(self):
         data = self.request.body
         data = str(data, 'utf8')
@@ -472,8 +476,6 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
         logger.info("账户信息=%s, 当前进程=%s, 当前进程的主进程=%s,  raw data from request is %s" %
                     (account_id, os.getpid(), os.getppid(), data))
 
-
-
         try:
             start_time = (datetime.date.today()).strftime('%Y-%m-%d %H:%M:%S')
             end_time = (datetime.datetime.now()).strftime('%Y-%m-%d %H:%M:%S')
@@ -526,7 +528,7 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
                             app_dict[app_info['appVersion']] = app_info
                     video_list = get_top_video_info(account_id=account_id,
                                                     url=get_high_quality_video_url,
-                                                    start_time=(now + datetime.timedelta(days=-2*high_quality_video_days)).
+                                                    start_time=(now + datetime.timedelta(days=-2 * high_quality_video_days)).
                                                     strftime("%Y-%m-%d %H:%M:%S"),
                                                     end_time=(now + datetime.timedelta(days=-high_quality_video_days)).
                                                     strftime("%Y-%m-%d %H:%M:%S"),
@@ -619,7 +621,7 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
 
                     video_info = get_top_video_info(account_id=account_id,
                                                     cnt=video_cnt,
-                                                    start_time=(now + datetime.timedelta(days=-2*high_quality_video_days)).
+                                                    start_time=(now + datetime.timedelta(days=-2 * high_quality_video_days)).
                                                     strftime("%Y-%m-%d %H:%M:%S"),
                                                     end_time=(now + datetime.timedelta(days=-high_quality_video_days)).
                                                     strftime("%Y-%m-%d %H:%M:%S"),
@@ -649,8 +651,8 @@ class AiCheckAndUpTOFullCreative(tornado.web.RequestHandler):
                             self.write(json.dumps(request))
                             self.flush()
         except Exception:
-            logger.error(traceback.format_exc())
-            self.write(json.dumps(traceback.format_exc()))
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
+            self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
             self.flush()
 
 
@@ -676,6 +678,7 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
     所有操作记录表中,添加status信息(已提交,成功,失败),和回调时的 message信息
 
     """
+
     def post(self):
         data = self.request.body
         data = str(data, 'utf8')
@@ -701,7 +704,7 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
                 video_list = get_top_video_info(account_id=account_id,
                                                 cnt=multi_app_id_programme_high_quality_video_cnt,
                                                 start_time=(datetime.datetime.now() + datetime.timedelta(
-                                                 days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
+                                                    days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
                                                 end_time=(datetime.datetime.now() + datetime.timedelta(days=-1)).
                                                 strftime("%Y-%m-%d %H:%M:%S"),
                                                 url=get_high_quality_video_url)
@@ -755,7 +758,7 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
                         app_id_cnt = 0
                         for i in range(0, len(general_video_list), 5):
                             if i + 5 < len(general_video_list):
-                                batch_general_video = general_video_list[i: i+batch_num]
+                                batch_general_video = general_video_list[i: i + batch_num]
                                 app_version = app_version_list[app_id_cnt]
                                 app_id = app_dict[app_version].get('appId', 'error')
                                 track_url = app_dict[app_version].get('trackUrl', 'error')
@@ -801,8 +804,6 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
                                                                 click_track_url=track_url)
                                 request = ai_strategy_request_parse(request_data)
 
-
-
                                 logger.info("account_id=%s, app_id=%s, 程序化高质量素材-通用视频,ai策略的返回信息:%s" % (account_id, app_id, request))
                     else:
                         logger.info("account_id=%s, 程序化高质量素材: 返回的视频中没有通用视频" % account_id)
@@ -812,7 +813,7 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
                 video_info = get_top_video_info(account_id=account_id,
                                                 cnt=programme_high_quality_video_cnt,
                                                 start_time=(datetime.datetime.now() + datetime.timedelta(
-                                                 days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
+                                                    days=-high_quality_video_days)).strftime("%Y-%m-%d %H:%M:%S"),
                                                 end_time=(datetime.datetime.now() + datetime.timedelta(days=-1)).
                                                 strftime("%Y-%m-%d %H:%M:%S"),
                                                 url=get_high_quality_video_url)
@@ -842,8 +843,8 @@ class AiProgramCreativeHighQualityMaterial(tornado.web.RequestHandler):
                         self.write(json.dumps(request))
                         self.flush()
         except Exception:
-            logger.error(traceback.format_exc())
-            self.write(json.dumps(traceback.format_exc()))
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
+            self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
             self.flush()
 
 
@@ -853,6 +854,7 @@ class AiProgramCreativeNewMaterial(tornado.web.RequestHandler):
     计划名称--新素材程序化
     timeTask: 每天上午10点执行 --(0 0 10 * * ?)
     """
+
     def post(self):
         data = self.request.body
         data = str(data, 'utf8')
@@ -1017,6 +1019,6 @@ class AiProgramCreativeNewMaterial(tornado.web.RequestHandler):
                         self.write(json.dumps(request))
                         self.flush()
         except Exception:
-            logger.error(traceback.format_exc())
-            self.write(json.dumps(traceback.format_exc()))
-            self.flush()
+            logger.error("account_id = %s, traceback is %s" % (account_id, traceback.format_exc()))
+            self.write(json.dumps({"account_id": account_id, "message": traceback.format_exc(), "code": -1}))
+            self.flush()