2019-01-26 18:02:44 +06:00
|
|
|
|
package com.nis.quartz;
|
|
|
|
|
|
|
2019-04-09 09:10:40 +08:00
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
2019-01-26 18:02:44 +06:00
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
import org.quartz.Job;
|
|
|
|
|
|
import org.quartz.JobDataMap;
|
|
|
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
|
|
|
import org.quartz.JobExecutionException;
|
2019-04-09 09:10:40 +08:00
|
|
|
|
import org.quartz.Scheduler;
|
|
|
|
|
|
import org.quartz.SchedulerException;
|
2019-01-26 18:02:44 +06:00
|
|
|
|
|
|
|
|
|
|
import com.nis.domain.ScheduleCfg;
|
2019-04-09 09:10:40 +08:00
|
|
|
|
import com.nis.util.Constants;
|
|
|
|
|
|
import com.nis.util.DateUtil;
|
|
|
|
|
|
import com.nis.util.DictUtils;
|
|
|
|
|
|
import com.nis.web.dao.SchedulerDao;
|
2019-01-26 18:02:44 +06:00
|
|
|
|
import com.nis.web.service.ScheduleService;
|
|
|
|
|
|
import com.nis.web.service.SpringContextHolder;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定时任务 真正执行类
|
|
|
|
|
|
* 配置状态下发
|
|
|
|
|
|
* 从trigger 的 jobDataMap 中取出 相关数据:compile,isValid
|
|
|
|
|
|
* @author fang
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class ScheduleStatusJob implements Job{
|
|
|
|
|
|
private static final Logger log = Logger.getLogger(ScheduleStatusJob.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
2019-04-09 09:10:40 +08:00
|
|
|
|
|
|
|
|
|
|
//全量同步状态
|
|
|
|
|
|
String currentStatus = DictUtils.getDictLabel("currrent_sync_status", "status","0");
|
|
|
|
|
|
//0:start:开始 1:init:初始化 2:doing:进行中
|
|
|
|
|
|
|
|
|
|
|
|
//全量同步过程中未执行的任务进入另一个job中,等待全量同步完成开始执行
|
|
|
|
|
|
if(currentStatus.equals("0") || currentStatus.equals("1")||currentStatus.equals("2")) {
|
|
|
|
|
|
//配置下发,并修改 配置表的状态,保存下发记录等
|
|
|
|
|
|
SchedulerDao schedulerDao = SpringContextHolder.getBean(SchedulerDao.class);
|
|
|
|
|
|
//从trigger中 获取 配置信息
|
|
|
|
|
|
JobDataMap jobDataMap = context.getTrigger().getJobDataMap();
|
|
|
|
|
|
boolean isValid = jobDataMap.getBoolean("isValid");
|
|
|
|
|
|
|
|
|
|
|
|
ScheduleCfg cfg = (ScheduleCfg)jobDataMap.get("cfg");
|
|
|
|
|
|
cfg.setId(null);//新入库一个任务
|
|
|
|
|
|
cfg.setType(2);//全量同步中未执行的任务
|
|
|
|
|
|
cfg.setUserRegion1("single"); //只执行一次
|
|
|
|
|
|
if(isValid) {
|
|
|
|
|
|
cfg.setCronValid("1900-01-01 01:01:01"); //无实际效果,仅仅为填充值
|
|
|
|
|
|
cfg.setCronInvalid("");
|
|
|
|
|
|
}else {
|
|
|
|
|
|
cfg.setCronValid("");
|
|
|
|
|
|
cfg.setCronInvalid("1900-01-01 01:01:01");//无实际效果,仅仅为填充值
|
|
|
|
|
|
}
|
|
|
|
|
|
schedulerDao.insert(cfg);
|
|
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
//从trigger中 获取 配置信息
|
|
|
|
|
|
JobDataMap jobDataMap = context.getTrigger().getJobDataMap();
|
|
|
|
|
|
boolean isValid = jobDataMap.getBoolean("isValid");
|
|
|
|
|
|
ScheduleCfg cfg = (ScheduleCfg)jobDataMap.get("cfg");
|
|
|
|
|
|
Integer compileId = cfg.getCompileId();
|
|
|
|
|
|
log.debug(String.format("任务开始执行,compileId:%s,isValid:%s",compileId,isValid ));
|
|
|
|
|
|
//配置下发,并修改 配置表的状态,保存下发记录等
|
|
|
|
|
|
ScheduleService scheduleService = SpringContextHolder.getBean(ScheduleService.class);
|
|
|
|
|
|
scheduleService.issueCompileInfo(cfg, isValid?1:0);
|
|
|
|
|
|
log.debug(String.format("任务开始执行,compileId:%s,isValid:%s",compileId,isValid ));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-26 18:02:44 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|