use of com.jeesuite.scheduler.AbstractJob in project jeesuite-libs by vakinge.
the class ZkJobRegistry method execCommond.
private void execCommond(MonitorCommond cmd) {
if (cmd == null)
return;
JobConfig config = schedulerConfgs.get(cmd.getJobName());
String key = cmd.getJobGroup() + ":" + cmd.getJobName();
final AbstractJob abstractJob = JobContext.getContext().getAllJobs().get(key);
if (MonitorCommond.TYPE_EXEC == cmd.getCmdType()) {
if (config.isRunning()) {
logger.info("任务正在执行中,请稍后再执行");
return;
}
if (abstractJob != null) {
JobContext.getContext().submitSyncTask(new Runnable() {
@Override
public void run() {
try {
logger.info("begin execute job[{}] by MonitorCommond", abstractJob.getJobName());
abstractJob.doJob(JobContext.getContext());
} catch (Exception e) {
logger.error(abstractJob.getJobName(), e);
}
}
});
} else {
logger.warn("Not found job by key:{} !!!!", key);
}
} else if (MonitorCommond.TYPE_STATUS_MOD == cmd.getCmdType() || MonitorCommond.TYPE_CRON_MOD == cmd.getCmdType()) {
if (config != null) {
if (MonitorCommond.TYPE_STATUS_MOD == cmd.getCmdType()) {
config.setActive("1".equals(cmd.getBody()));
} else {
try {
new CronExpression(cmd.getBody().toString());
} catch (Exception e) {
throw new RuntimeException("cron表达式格式错误");
}
abstractJob.resetTriggerCronExpr(cmd.getBody().toString());
config.setCronExpr(cmd.getBody().toString());
}
updateJobConfig(config);
if (JobContext.getContext().getConfigPersistHandler() != null) {
JobContext.getContext().getConfigPersistHandler().persist(config);
}
}
}
}
Aggregations