use of com.jeesuite.scheduler.model.JobConfig in project jeesuite-libs by vakinge.
the class AbstractJob method execute.
public void execute() {
// 避免InstanceFactory还未初始化,就执行
InstanceFactory.waitUtilInitialized();
JobConfig schConf = JobContext.getContext().getRegistry().getConf(jobName, false);
if (currentNodeIgnore(schConf))
return;
Date beginTime = null;
Exception exception = null;
try {
// 更新状态
beginTime = getPreviousFireTime();
JobContext.getContext().getRegistry().setRuning(jobName, beginTime);
logger.debug("Job_{} at node[{}] execute begin...", jobName, JobContext.getContext().getNodeId());
// 执行
doJob(JobContext.getContext());
logger.debug("Job_{} at node[{}] execute finish", jobName, JobContext.getContext().getNodeId());
} catch (Exception e) {
// 重试
if (retries > 0)
JobContext.getContext().getRetryProcessor().submit(this, retries);
logger.error("Job_" + jobName + " execute error", e);
exception = e;
}
// 执行次数累加1
runCount.incrementAndGet();
Date nextFireTime = getTrigger().getNextFireTime();
JobContext.getContext().getRegistry().setStoping(jobName, nextFireTime, exception);
// 运行日志持久化
doJobLogPersist(schConf, exception, nextFireTime);
// 重置cronTrigger,重新获取才会更新previousFireTime,nextFireTime
cronTrigger = null;
}
use of com.jeesuite.scheduler.model.JobConfig in project jeesuite-libs by vakinge.
the class NullJobRegistry method setRuning.
@Override
public void setRuning(String jobName, Date fireTime) {
JobConfig config = schedulerConfgs.get(jobName);
config.setRunning(true);
config.setLastFireTime(fireTime);
}
use of com.jeesuite.scheduler.model.JobConfig in project jeesuite-libs by vakinge.
the class AbstractJob method init.
public void init() {
triggerName = jobName + "Trigger";
triggerKey = new TriggerKey(triggerName, group);
JobConfig jobConfg = new JobConfig(group, jobName, cronExpr);
// 从持久化配置合并
if (JobContext.getContext().getConfigPersistHandler() != null) {
JobContext.getContext().getConfigPersistHandler().merge(jobConfg);
}
JobContext.getContext().getRegistry().register(jobConfg);
logger.info("Initialized Job_{} OK!!", jobName);
}
use of com.jeesuite.scheduler.model.JobConfig in project jeesuite-libs by vakinge.
the class NullJobRegistry method setStoping.
@Override
public void setStoping(String jobName, Date nextFireTime, Exception e) {
JobConfig config = schedulerConfgs.get(jobName);
config.setRunning(false);
config.setNextFireTime(nextFireTime);
}
use of com.jeesuite.scheduler.model.JobConfig in project jeesuite-libs by vakinge.
the class SchedulerMonitor method getJobGroupInfo.
public JobGroupInfo getJobGroupInfo(String groupName) {
if (StringUtils.isBlank(groupName)) {
logger.warn("getJobGroupInfo groupName is required");
return null;
}
JobGroupInfo groupInfo = new JobGroupInfo();
groupInfo.setName(groupName);
//
String path = ZkJobRegistry.ROOT + groupName;
List<String> children = zkClient.getChildren(path);
for (String child : children) {
if ("nodes".equals(child)) {
path = ZkJobRegistry.ROOT + groupName + "/nodes";
groupInfo.setClusterNodes(zkClient.getChildren(path));
} else {
path = ZkJobRegistry.ROOT + groupName + "/" + child;
Object data = zkClient.readData(path);
if (data != null) {
JobConfig jobConfig = JsonUtils.toObject(data.toString(), JobConfig.class);
groupInfo.getJobs().add(jobConfig);
}
}
}
if (groupInfo.getClusterNodes().size() > 0) {
return groupInfo;
}
return null;
}
Aggregations