From 301017226e61aa39c8b40e780ca244eeddd073d4 Mon Sep 17 00:00:00 2001
From: cy <1664593601@qq.com>
Date: 星期日, 09 十月 2022 14:14:54 +0800
Subject: [PATCH] feat(schedule): 定时任务视频拉取

---
 recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java
index 15886e7..69be7b3 100644
--- a/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java
+++ b/recommend-video/src/main/java/com/iplatform/recvideo/scheduler/VideoLoadScheduler.java
@@ -1,17 +1,77 @@
 package com.iplatform.recvideo.scheduler;
 
+import com.iplatform.core.BeanContextAware;
+import com.iplatform.recvideo.VideoLoader;
 import com.iplatform.recvideo.VideoScheduler;
+import com.iplatform.recvideo.config.VideoSimilarProperties;
+import com.iplatform.recvideo.service.VideoLoaderServiceImpl;
+import com.iplatform.recvideo.support.DefaultVideoLoader;
+import com.walker.connector.Address;
+import com.walker.connector.support.DatabaseConnector;
+import com.walker.connector.util.ConnectorUtils;
 import com.walker.store.AbstractStore;
 import com.walker.store.task.GatherTask;
 
+/**
+ * 鐭棰戦噰闆�(鍔犺浇鎷疯礉)璋冨害浠诲姟瀹炵幇銆�
+ * @author 鏃跺厠鑻�
+ * @date 2022-09-30
+ */
 public class VideoLoadScheduler extends VideoScheduler {
+
+    private VideoLoader videoLoader= null;
+    private int failedCount = 0;
+
+    private Address srcAddress; // 浠庝笟鍔$郴缁熸暟鎹簱鍔犺浇瑙嗛闆嗗悎璁板綍
 
     public VideoLoadScheduler(int id, String name){
         super(id, name);
+        VideoSimilarProperties videoSimilarProperties = BeanContextAware.getBeanByType(VideoSimilarProperties.class);
+        srcAddress = new Address();
+        srcAddress.setUrl(videoSimilarProperties.getBusinessDatasourceUrl());
+        srcAddress.setPort(videoSimilarProperties.getBusinessDatasourcePort());
+        srcAddress.setService(videoSimilarProperties.getBusinessDatasourceService());
+        srcAddress.setAuthentication(videoSimilarProperties.getBusinessDatasourceAuthentication());
+        srcAddress.setCertification(videoSimilarProperties.getBusinessDatasourceCertification());
     }
 
     @Override
     protected GatherTask providerTask(AbstractStore store) {
         return null;
     }
+
+    @Override
+    protected Object onProcess(Object[] inputParams) throws Exception {
+        if(this.videoLoader == null){
+            DefaultVideoLoader defaultVideoLoader = new DefaultVideoLoader();
+            defaultVideoLoader.setVideoLoaderService(BeanContextAware.getBeanByType(VideoLoaderServiceImpl.class));
+            defaultVideoLoader.setDatabaseConnector(this.createMySqlConnector(this.srcAddress));
+            defaultVideoLoader.startup(false);
+            this.videoLoader = defaultVideoLoader;
+            logger.debug("鍒涘缓'DefaultVideoLoader': " + defaultVideoLoader.getClass());
+        }
+
+        try{
+            int result = this.videoLoader.execute();
+            if(result == 1){
+                logger.info("鎴愬姛鎵ц涓�娆$煭瑙嗛閲囬泦");
+                return SUCCESS;
+            }
+            logger.debug("videoLoader.execute() = -1锛岀嚎绋嬪噯澶囦紤鐪�");
+            return null;
+        }catch (Exception ex){
+            logger.error("VideoLoader.execute()鎶ラ敊: " + ex.getMessage(), ex);
+            this.failedCount ++;
+            if(this.failedCount > 3){
+                // 濡傛灉鎶ラ敊瓒呰繃澶氭锛岃繑鍥炵┖锛岃绾跨▼浼戠湢涓�涓�
+                this.failedCount = 0;
+            }
+            return null;
+        }
+    }
+
+    private DatabaseConnector createMySqlConnector(Address address){
+        DatabaseConnector connector = ConnectorUtils.createMySQLConnector(address);
+        return connector;
+    }
 }

--
Gitblit v1.9.1