package com.iplatform.recvideo.api; import com.iplatform.core.BeanContextAware; import com.iplatform.recvideo.config.VideoSimilarProperties; import com.iplatform.recvideo.scheduler.VideoSearchScheduler; import com.iplatform.recvideo.service.VideoExecutorServiceImpl; import com.iplatform.recvideo.support.DefaultSimilarExecutor; import com.walker.scheduler.ScheduleEngine; import com.walker.scheduler.util.OptionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.util.ArrayList; import java.util.List; @RestController @RequestMapping("/debug/video") public class DemoDebug { private RestTemplate restTemplate; private VideoSimilarProperties videoSimilarProperties; private VideoExecutorServiceImpl videoExecutorService; private VideoSearchScheduler videoSearchScheduler = null; private DefaultSimilarExecutor similarExecutor = null; @Autowired public DemoDebug(RestTemplate restTemplate , VideoSimilarProperties videoSimilarProperties , VideoExecutorServiceImpl videoExecutorService){ this.restTemplate = restTemplate; this.videoSimilarProperties = videoSimilarProperties; this.videoExecutorService = videoExecutorService; } @RequestMapping("/start_scheduler_1") public String testStartVideoSearchScheduler(){ if(this.videoSearchScheduler != null){ this.videoSearchScheduler.stop(); this.videoSearchScheduler = null; } List timeRanges = new ArrayList(1); timeRanges.add(new Integer[]{10,11}); timeRanges.add(new Integer[]{12,12}); this.videoSearchScheduler = new VideoSearchScheduler(100, "视频相似度分析调度任务"); this.videoSearchScheduler.setOption(OptionUtils.combineEveryDayHourRange(timeRanges)); this.videoSearchScheduler.setScheduleEngine(BeanContextAware.getBeanByType(ScheduleEngine.class)); this.videoSearchScheduler.setMaxFailedTimes(10); this.videoSearchScheduler.start(); return this.videoSearchScheduler.getName() + " 启动"; } /** * 该测试用于模拟调度任务,每次调用一次执行器方法,批量处理一张图片数据。

* 最终完成一批多个视频的相似度检索并写入数据库中。 * @return * @date 2022-09-24 */ @RequestMapping("/test1") public String testSimilarExecutor(){ // String if(similarExecutor == null){ this.similarExecutor = new DefaultSimilarExecutor(); this.similarExecutor.setVideoExecutorService(this.videoExecutorService); this.similarExecutor.setRestTemplate(this.restTemplate); this.similarExecutor.setRemoteUrl(this.videoSimilarProperties.getAiService()); this.similarExecutor.startup(this.videoSimilarProperties.getDataFolder() , "20220921", this.videoSimilarProperties.getTopN(), true); // 注意:这里测试模式 } try { this.similarExecutor.execute(); return "成功执行一次"; } catch (Exception e) { throw new RuntimeException(e); } } }