浏览代码

Merge branch 'feature_gufengshou_20240125_pid' into pre-master

gufengshou1 1 年之前
父节点
当前提交
a3123bd951

+ 0 - 61
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/container/AbTestConfigContainer.java

@@ -25,68 +25,10 @@ public class AbTestConfigContainer {
     @Value("${ad.abtest.time.plan.code:555}")
     String adTestCode;
 
-    //List<Tuple<Integer>>
-    Map<String,List<JSONObject>> adTimePlanMap=new HashMap<>();
-//    Map<Integer,Map<String,List<JSONObject>>> appAdTimePlanMap=new ConcurrentHashMap<>() ;
-//    @PostConstruct
-//    public void initContainer(){
-//        Timer timer = new Timer();
-//        timer.schedule(new TimerTask() {
-//            @Override
-//            public void run() {
-//                try {
-////                    for (Integer appType:appAdTimePlanMap.keySet()){
-////                        initMap(appType,"ab_test002");
-////                    }
-//                    initMap(3,"ab_test002");
-////                    log.info("svc=refresh_adTimePlanMap appAdTimePlanMap={}",JSONObject.toJSONString(appAdTimePlanMap));
-//                    log.info("svc=refresh_adTimePlanMap adTimePlanMap={}",JSONObject.toJSONString(adTimePlanMap));
-//                }catch (Exception e){
-//                    e.printStackTrace();
-//                }
-//            }
-//        }, 0, 1000*30);
-//    }
-
-//    public void initMap(Integer appType,String typeValue){
-//        AbTestConfigRequest request=new  AbTestConfigRequest();
-//        if(appType==null){
-//            request.setAppType(0);
-//        }else{
-//            request.setAppType(appType);
-//        }
-//        request.setTypeValue(typeValue);
-//        CommonResponse<JSONObject> response=longVideoFeign.getAbTestConfig(request);
-//        log.info("svc=initAdTimePlanMap_getConfigFromLongVideoApi response={}",JSONObject.toJSONString(response));
-//        JSONObject object=response.getData();
-//        for(Map.Entry<String,Object> entry:object.getInnerMap().entrySet()){
-//            for(Map<String,Object> map:(List<Map>)entry.getValue()){
-//                if(adTestCode.equals(map.get("abExpCode").toString())){
-//                    adTimePlanMap=JSONObject.parseObject(map.get("configValue").toString(),Map.class);
-//                    break;
-//                }
-//            }
-//        }
-//    }
-
-//    public Boolean containsCode(String code){
-//        return adTimePlanMap.keySet().contains(code);
-//    }
-
     public Boolean containsCode(Map<String,List<JSONObject>> configMap,String code){
         return configMap.keySet().contains(code);
     }
 
-//    public Boolean inWithoutAdTime(String code,Integer hourOfDay){
-//        Boolean flag=false;
-//        for(JSONObject object:adTimePlanMap.getOrDefault(code,new ArrayList<>())){
-//            if(object.getInteger("x")<=hourOfDay&&hourOfDay<object.getInteger("y")){
-//                return true;
-//            }
-//        }
-//        return flag;
-//    }
-
     public Boolean inWithoutAdTime(Map<String,List<JSONObject>> abConfigMap,String code,Integer hourOfDay){
         Boolean flag=false;
         for(JSONObject object:abConfigMap.getOrDefault(code,new ArrayList<>())){
@@ -94,19 +36,16 @@ public class AbTestConfigContainer {
                 return true;
             }
         }
-        //
         return flag;
     }
 
     public Boolean inAdTimeTest(JSONObject abExpInfo){
-        //todo youhua
         List<Map<String,Object>> mapList=(List)abExpInfo.get("ab_test002");
         for(Map<String,Object> map:mapList){
             if(adTestCode.equals(map.getOrDefault("abExpCode",""))){
                 return true;
             }
         }
-        //
         return false;
     }
 

+ 13 - 8
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/container/PidLambdaContainer.java

@@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit;
 public class PidLambdaContainer {
     private final static Logger log = LoggerFactory.getLogger(PidLambdaContainer.class);
 
-    private static final int SCHEDULE_PERIOD = 1;
+    private static final int SCHEDULE_PERIOD = 10;
     private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
     @Value("${model.oss.internal.endpoint:oss-cn-hangzhou.aliyuncs.com}")
     String endpoint = "";
@@ -115,12 +115,17 @@ public class PidLambdaContainer {
 
     private void writeLambdaFileToOss(){
         //先不考虑各种更新失败及重复更新问题。
-        String tempFile=lambdaFileName+"_temp";
-        String content= JSONObject.toJSONString(lambdaCache);
-        PutObjectResult putObjectResult=client.putObject(bucketName,tempFile,new ByteArrayInputStream(content.getBytes()));
-        CopyObjectResult copyObjectResult=client.copyObject(bucketName, tempFile, bucketName, lambdaFileName);
-        this.cacheDate= copyObjectResult.getLastModified();
-        client.deleteObject(bucketName, tempFile);
+        try {
+            String tempFile=lambdaFileName+"_temp";
+            String content= JSONObject.toJSONString(lambdaCache);
+            PutObjectResult putObjectResult=client.putObject(bucketName,tempFile,new ByteArrayInputStream(content.getBytes()));
+            CopyObjectResult copyObjectResult=client.copyObject(bucketName, tempFile, bucketName, lambdaFileName);
+            this.cacheDate= copyObjectResult.getLastModified();
+            client.deleteObject(bucketName, tempFile);
+        }catch (Exception e){
+            log.error("svc=writeLambdaFileToOss status=failed error={}", Arrays.toString(e.getStackTrace()));
+            e.printStackTrace();
+        }
     }
 
     private void loadLambdaFile(){
@@ -128,7 +133,6 @@ public class PidLambdaContainer {
             OSSObject object=client.getObject(bucketName,lambdaFileName);
             if(object==null) return;
             if(cacheDate!=null&& !cacheDate.before(object.getObjectMetadata().getLastModified())) return;
-//            if(cacheDate!=null&& cacheDate.after(object.getObjectMetadata().getLastModified())) return;
             StringBuilder builder=new StringBuilder();
             InputStream is=object.getObjectContent();
             InputStreamReader isr=new InputStreamReader(is);
@@ -140,6 +144,7 @@ public class PidLambdaContainer {
             lambdaCache=JSONObject.parseObject(builder.toString(),new TypeReference<ConcurrentHashMap<Long,Double>>(){});
             this.cacheDate=object.getObjectMetadata().getLastModified();
         }catch (Exception e){
+            log.error("svc=loadLambdaFile status=failed error={}", Arrays.toString(e.getStackTrace()));
             e.printStackTrace();
         }
     }