Search in sources :

Example 6 with JobConfig

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;
}
Also used : JobConfig(com.jeesuite.scheduler.model.JobConfig) Date(java.util.Date) SchedulerException(org.quartz.SchedulerException)

Example 7 with JobConfig

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);
}
Also used : JobConfig(com.jeesuite.scheduler.model.JobConfig)

Example 8 with JobConfig

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);
}
Also used : TriggerKey(org.quartz.TriggerKey) JobConfig(com.jeesuite.scheduler.model.JobConfig)

Example 9 with JobConfig

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);
}
Also used : JobConfig(com.jeesuite.scheduler.model.JobConfig)

Example 10 with JobConfig

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;
}
Also used : JobGroupInfo(com.jeesuite.scheduler.model.JobGroupInfo) JobConfig(com.jeesuite.scheduler.model.JobConfig)

Aggregations

JobConfig (com.jeesuite.scheduler.model.JobConfig)12 AbstractJob (com.jeesuite.scheduler.AbstractJob)1 JobGroupInfo (com.jeesuite.scheduler.model.JobGroupInfo)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 IZkDataListener (org.I0Itec.zkclient.IZkDataListener)1 ZkClient (org.I0Itec.zkclient.ZkClient)1 ZkConnection (org.I0Itec.zkclient.ZkConnection)1 CronExpression (org.quartz.CronExpression)1 SchedulerException (org.quartz.SchedulerException)1 TriggerKey (org.quartz.TriggerKey)1