shikeying
2022-09-30 a78b76b664830a1ac691396d5cb64166c6919ff1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.iplatform.recvideo.scheduler;
 
import com.iplatform.core.BeanContextAware;
import com.iplatform.recvideo.VideoLoader;
import com.iplatform.recvideo.VideoScheduler;
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);
        srcAddress = new Address();
        srcAddress.setUrl("127.0.0.1");
        srcAddress.setPort(3306);
        srcAddress.setAuthentication("root");
        srcAddress.setCertification("123456");
    }
 
    @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;
    }
}