Search in sources :

Example 91 with TriggerKey

use of org.quartz.TriggerKey in project OpenOLAT by OpenOLAT.

the class StatisticsAdminController method refreshUIState.

private void refreshUIState() {
    log_.info("refreshUIState: schedulerFactoryBean found");
    boolean enabled = false;
    String cronExpression = "";
    Trigger.TriggerState triggerState;
    try {
        TriggerKey triggerKey = new TriggerKey("updateStatisticsTrigger", null);
        triggerState = scheduler.getTriggerState(triggerKey);
        enabled = triggerState != Trigger.TriggerState.NONE && triggerState != Trigger.TriggerState.ERROR;
        Trigger trigger = scheduler.getTrigger(triggerKey);
        if (trigger == null) {
            enabled &= false;
        } else {
            enabled &= trigger.getJobKey().getName().equals("org.olat.statistics.job.enabled");
            if (trigger instanceof CronTrigger) {
                log_.info("refreshUIState: org.olat.statistics.job.enabled check, enabled now: " + enabled);
                cronExpression = ((CronTrigger) trigger).getCronExpression();
            }
        }
        log_.info("refreshUIState: updateStatisticsTrigger state was " + triggerState + ", enabled now: " + enabled);
    } catch (SchedulerException e) {
        log_.warn("refreshUIState: Got a SchedulerException while asking for the updateStatisticsTrigger's state", e);
    }
    StatisticUpdateManager statisticUpdateManager = getStatisticUpdateManager();
    if (statisticUpdateManager == null) {
        log_.info("refreshUIState: statisticUpdateManager not configured");
        enabled = false;
    } else {
        enabled &= statisticUpdateManager.isEnabled();
        log_.info("refreshUIState: statisticUpdateManager configured, enabled now: " + enabled);
    }
    if (enabled) {
        content.contextPut("status", getTranslator().translate("statistics.status.enabled", new String[] { cronExpression }));
    } else {
        content.contextPut("status", getTranslator().translate("statistics.status.disabled"));
    }
    content.contextPut("statisticEnabled", enabled);
    recalcLastUpdated();
    updateStatisticUpdateOngoingFlag();
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) StatisticUpdateManager(org.olat.course.statistic.StatisticUpdateManager)

Example 92 with TriggerKey

use of org.quartz.TriggerKey in project xwiki-platform by xwiki.

the class SchedulerPlugin method getTrigger.

/**
 * Get Trigger object of the given job
 *
 * @param object the unwrapped XObject to be retrieve the trigger for
 * @param context the XWiki context
 * @return the trigger object of the given job
 */
private Trigger getTrigger(BaseObject object, XWikiContext context) throws SchedulerPluginException {
    String job = getObjectUniqueId(object, context);
    Trigger trigger;
    try {
        trigger = getScheduler().getTrigger(new TriggerKey(job));
    } catch (SchedulerException e) {
        throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while getting trigger for job " + job, e);
    }
    if (trigger == null) {
        throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_DOES_NOT_EXITS, "Job does not exists");
    }
    return trigger;
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 93 with TriggerKey

use of org.quartz.TriggerKey in project syncope by apache.

the class TaskDataBinderImpl method setExecTime.

private void setExecTime(final SchedTaskTO taskTO, final Task task) {
    taskTO.setLastExec(taskTO.getStart());
    String triggerName = JobNamer.getTriggerName(JobNamer.getJobKey(task).getName());
    try {
        Trigger trigger = scheduler.getScheduler().getTrigger(new TriggerKey(triggerName, Scheduler.DEFAULT_GROUP));
        if (trigger != null) {
            taskTO.setLastExec(trigger.getPreviousFireTime());
            taskTO.setNextExec(trigger.getNextFireTime());
        }
    } catch (SchedulerException e) {
        LOG.warn("While trying to get to " + triggerName, e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 94 with TriggerKey

use of org.quartz.TriggerKey in project spring-cloud-framework by zhuwj921.

the class JobAndTriggerImpl method getJobAndTriggerDetails.

public PageInfo<JobAndTrigger> getJobAndTriggerDetails(int pageNum, int pageSize) throws SchedulerException {
    PageHelper.startPage(pageNum, pageSize);
    List<JobAndTrigger> list = jobAndTriggerDAO.getJobAndTriggerDetails();
    Iterator<JobAndTrigger> listIt = list.iterator();
    while (listIt.hasNext()) {
        JobAndTrigger jobAndTrigger = listIt.next();
        Trigger.TriggerState triggerState = scheduler.getTriggerState(new TriggerKey(jobAndTrigger.getTriggerName(), jobAndTrigger.getTriggerGroup()));
        if (triggerState == Trigger.TriggerState.NORMAL) {
            jobAndTrigger.setRunning(true);
        }
    }
    PageInfo<JobAndTrigger> page = new PageInfo<JobAndTrigger>(list);
    return page;
}
Also used : TriggerKey(org.quartz.TriggerKey) PageInfo(com.github.pagehelper.PageInfo) Trigger(org.quartz.Trigger) JobAndTrigger(com.cloud.zhuwj.quartz.domain.JobAndTrigger) JobAndTrigger(com.cloud.zhuwj.quartz.domain.JobAndTrigger)

Example 95 with TriggerKey

use of org.quartz.TriggerKey in project dubidubi by lzzzz4.

the class Quartz method updateJobTime.

public static void updateJobTime(String jobName, String jobGroupName, String triggerName, String triggerGroupName, String cron) {
    try {
        Scheduler sched = schedulerFactory.getScheduler();
        TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);
        CronTrigger trigger = (CronTrigger) sched.getTrigger(triggerKey);
        if (trigger == null) {
            return;
        }
        String oldTime = trigger.getCronExpression();
        if (!oldTime.equalsIgnoreCase(cron)) {
            /**
             * 方式一 :调用 rescheduleJob 开始
             */
            // 触发器
            TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
            // 触发器名,触发器组
            triggerBuilder.withIdentity(triggerName, triggerGroupName);
            triggerBuilder.startNow();
            // 触发器时间设定
            triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cron));
            // 创建Trigger对象
            trigger = (CronTrigger) triggerBuilder.build();
            // 方式一 :修改一个任务的触发时间
            sched.rescheduleJob(triggerKey, trigger);
        /**
         * 方式一 :调用 rescheduleJob 结束
         */
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler)

Aggregations

TriggerKey (org.quartz.TriggerKey)112 Trigger (org.quartz.Trigger)49 JobKey (org.quartz.JobKey)30 SchedulerException (org.quartz.SchedulerException)30 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Test (org.junit.Test)18 Scheduler (org.quartz.Scheduler)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4