This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/quartz/ScheduleStatusJob.java
段冬梅 589cf100ee 俄文OK翻译;
定时任务错误信息打印;
恢复白名单被覆盖的logger.error;
2019-04-24 16:01:40 +08:00

83 lines
2.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nis.quartz;
import java.util.Date;
import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import com.nis.domain.ScheduleCfg;
import com.nis.util.Constants;
import com.nis.util.DateUtil;
import com.nis.util.DictUtils;
import com.nis.web.dao.SchedulerDao;
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 {
//全量同步状态
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);
try {
scheduleService.issueCompileInfo(cfg, isValid?1:0);
} catch (Exception e) {
e.printStackTrace();
log.error("定时任务"+cfg.getId()+"执行失败",e);
}finally {
log.debug(String.format("任务执行完成compileId:%s,isValid:%s",compileId,isValid ));
}
}
}
}