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; } }