定时任务任务表增加type:1-正常任务;2-全量同步执行时未执行的任务。

增加全量同步时未执行任务的扫描
全量同步时,业务无数据也需要下发{}至服务端。
This commit is contained in:
段冬梅
2019-04-09 09:10:40 +08:00
parent 08dd0f3868
commit bf00ccd875
13 changed files with 846 additions and 77 deletions

View File

@@ -40,20 +40,65 @@ public class ScheduleService extends BaseService{
ScheduleExceInfo exceNew = dao.findScheduleExceNew(se);
//2、如果已经下发直接下发状态否则下发配置
Integer issueResult = 1;
//是否下发内容
Integer isIssueContent = 1;
String errorInfo = null;
String tableName = cfg.getTableName();
SchedulerTaskUtil scheduler = new SchedulerTaskUtil();
boolean udpateConfigStatus = false;
try {
if(isValid == 1 && (exceNew == null || exceNew.getIsIssue() == 1)) {//生效配置需要下发
udpateConfigStatus = scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, 1,configSynchronizationDao);
logger.info(String.format("定时器下发配置内容compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
}else{//只需修改状态
udpateConfigStatus = scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, 0,configSynchronizationDao);
logger.info(String.format("定时器修改配置状态compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
//生效配置需要下发
if(isValid == 1 && (exceNew == null || exceNew.getIsIssue() == 1)) {
isIssueContent=1;
}else {
//之下发状态
isIssueContent=0;
}
//首先对数据库操作
if(exceNew == null) {
//新增exce_new 表状态
exceNew = new ScheduleExceInfo();
exceNew.setCompileId(compileId);
exceNew.setIssueStatus(isValid);
exceNew.setExceTime(new Date());
exceNew.setIssueResult(issueResult);
exceNew.setErrorInfo(errorInfo);
exceNew.setIsIssue(0);
exceNew.setScheduleId(cfg.getId());
dao.insertScheduleExceNew(exceNew);
}else {
//修改 exce_new 表状态
exceNew.setExceTime(new Date());
exceNew.setIssueResult(issueResult);
exceNew.setErrorInfo(errorInfo);
exceNew.setScheduleId(cfg.getId());
dao.updateScheduleExceNew(exceNew);
}
ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil();
List<Map<String,Object>> serviceList = serviceTemplate.getServiceListByServiceId(cfg.getServiceId());
//根据编译ID查询配置表中的配置信息
for(Map<String,Object> service:serviceList){
//获取业务下的配置域
List<Map<String,Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
//查询子域配置详情
if(cfgList!=null){
for(Map<String,Object> m:cfgList){
String regionTable = m.get("tableName").toString();
//更新配置域表的isValid字段
dao.updateCfgTableStatus(regionTable, compileId, isValid);
}
}
}
//3、更新 配置表的 isValid 字段,添加 exce_log 记录
dao.insertScheduleExceLog(exceNew);
dao.updateCfgTableStatus(tableName, compileId, isValid);
//数据库操作完成后与服务端交互
try {
udpateConfigStatus = scheduler.updateConfigByServiceAndCompile(cfg.getServiceId(), compileId, isValid, isIssueContent,configSynchronizationDao);
logger.info(String.format("定时器下发配置内容compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
} catch (NoSuchFieldException e) {
udpateConfigStatus = false;
e.printStackTrace();
@@ -70,46 +115,6 @@ public class ScheduleService extends BaseService{
// logger.info(String.format("配置状态更新compileId:%s,isValid:%s,issueResult:%s,errorInfo:%s",compileId,isValid,issueResult,errorInfo));
if(udpateConfigStatus){//配置更新成功
if(exceNew == null) {
//新增exce_new 表状态
exceNew = new ScheduleExceInfo();
exceNew.setCompileId(compileId);
exceNew.setIssueStatus(isValid);
exceNew.setExceTime(new Date());
exceNew.setIssueResult(issueResult);
exceNew.setErrorInfo(errorInfo);
exceNew.setIsIssue(0);
exceNew.setScheduleId(cfg.getId());
dao.insertScheduleExceNew(exceNew);
}else {
//修改 exce_new 表状态
exceNew.setExceTime(new Date());
exceNew.setIssueResult(issueResult);
exceNew.setErrorInfo(errorInfo);
exceNew.setScheduleId(cfg.getId());
dao.updateScheduleExceNew(exceNew);
}
ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil();
List<Map<String,Object>> serviceList = serviceTemplate.getServiceListByServiceId(cfg.getServiceId());
//根据编译ID查询配置表中的配置信息
for(Map<String,Object> service:serviceList){
//获取业务下的配置域
List<Map<String,Object>> cfgList = (List<Map<String, Object>>) service.get("cfgList");
//查询子域配置详情
if(cfgList!=null){
for(Map<String,Object> m:cfgList){
String regionTable = m.get("tableName").toString();
//更新配置域表的isValid字段
dao.updateCfgTableStatus(regionTable, compileId, isValid);
}
}
}
//3、更新 配置表的 isValid 字段,添加 exce_log 记录
dao.insertScheduleExceLog(exceNew);
dao.updateCfgTableStatus(tableName, compileId, isValid);
}
}

View File

@@ -155,8 +155,8 @@ public class ConfigSynchronizationService extends BaseService{
Page<BaseCfg> page=new Page<BaseCfg>(request,response,Constants.MAAT_JSON_SEND_SIZE,"a");
handleCallbackData(className,page,entity,request,response,false);
}
//如果业务没有配置数据,并且为最后一个业务,需要发送给服务接口一个结束标识
if(!isFinished && lastServiceTag){
//最后一个业务,发送一个结束标识
if(lastServiceTag){
String json = "{}";
//如果是所有业务全量同步需要发送一个service=-1的请求有助于服务端删除分组复用配置
if(StringUtil.isEmpty(serviceIdCondition)){
@@ -477,7 +477,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
}
@@ -649,7 +649,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
}
@@ -839,7 +839,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
}
@@ -1010,7 +1010,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
}
@@ -1339,7 +1339,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
@@ -1548,7 +1548,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
@@ -1703,7 +1703,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+compileId+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
@@ -1859,7 +1859,7 @@ public class ConfigSynchronizationService extends BaseService{
//调用服务接口配置全量更新
isFinished = ((!hasData)&&lastServiceTag)?true:false;
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+compileId+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,null);
logger.info("全量下发响应信息:"+result.toString());
}
@@ -2021,7 +2021,7 @@ public class ConfigSynchronizationService extends BaseService{
FileUtils.writeToFile("/home/ceiec/configSync/"+DateUtils.getDate("yyyy-MM-dd")+"/"+entity.getServiceId()+"_"+page.getPageNo()+"_"+System.currentTimeMillis()+".json", json, false);
//调用服务接口同步回调类配置
isFinished = ((!hasData)&&lastServiceTag)?true:false;
JSONObject result = ConfigServiceUtil.configSync(json,2,entity.getServiceId(),entity.getTableName(),isFinished?"FINISHED":null);
JSONObject result = ConfigServiceUtil.configSync(json,2,entity.getServiceId(),entity.getTableName(),null);
logger.info("全量下发响应信息:"+result.toString());
}
}