shikeying
2022-09-27 26f5dd8ef80e5671cda8fc0e6c0d0298c4e678ff
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
75
76
77
78
79
80
81
82
83
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<Integer[]> timeRanges = new ArrayList<Integer[]>(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() + " 启动";
    }
 
    /**
     * 该测试用于模拟调度任务,每次调用一次执行器方法,批量处理一张图片数据。<p></p>
     * 最终完成一批多个视频的相似度检索并写入数据库中。
     * @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);
        }
    }
 
}