Search in sources :

Example 1 with AbstractJob

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

Aggregations

AbstractJob (com.jeesuite.scheduler.AbstractJob)1 JobConfig (com.jeesuite.scheduler.model.JobConfig)1 CronExpression (org.quartz.CronExpression)1