shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.scheduler;
 
import com.walker.scheduler.impl.ForeverScheduler;
 
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
 
/**
 * 根据ID筛选数据处理,调度实现。
 * @date 2023-03-14
 */
public class IdForeverScheduler extends ForeverScheduler {
 
    public IdForeverScheduler(int id, String name) {
        super(id, name);
    }
 
    @Override
    protected Object onProcess(Object[] inputParams) throws Exception {
        // 获取助力任务集合
        List<Integer> data = this.acquireRandomDataList(this.getId());
        if(data == null || data.size() == 0){
            // 模拟没有获取到数据,休眠
            logger.info("'{}'已处理完数据,业务没有获取到任何数据,睡眠一次,默认10分钟", this.getName());
            return null;
        }
 
        for(Integer i : data){
            // 这里处理业务记录:调用接口、更新状态等
            logger.info("{}调用接口一次,data = {}", this.getName(), i);
        }
        // 返回本次数据,让任务继续
        return data;
    }
 
    private List<Integer> acquireRandomDataList(int number){
        List<Integer> list = new LinkedList<>();
        Integer temp = null;
        for(int i=0; i<20; i++){
            temp = this.random.nextInt(20);
            if(temp.intValue() == number){
                list.add(temp);
            }
        }
        return list;
    }
 
    private int count = 0;
    private Random random = new Random(999);
}