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