Search in sources :

Example 16 with TriggerKey

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

the class ReportDataBinderImpl method getReportTO.

@Override
public ReportTO getReportTO(final Report report) {
    ReportTO reportTO = new ReportTO();
    reportTO.setKey(report.getKey());
    reportTO.setTemplate(report.getTemplate().getKey());
    BeanUtils.copyProperties(report, reportTO, IGNORE_REPORT_PROPERTIES);
    reportTO.getReportlets().addAll(report.getReportlets().stream().map(Entity::getKey).collect(Collectors.toList()));
    ReportExec latestExec = reportExecDAO.findLatestStarted(report);
    if (latestExec == null) {
        reportTO.setLatestExecStatus(StringUtils.EMPTY);
    } else {
        reportTO.setLatestExecStatus(latestExec.getStatus());
        reportTO.setStart(latestExec.getStart());
        reportTO.setEnd(latestExec.getEnd());
        reportTO.setLastExec(reportTO.getStart());
    }
    reportTO.getExecutions().addAll(report.getExecs().stream().map(reportExec -> getExecTO(reportExec)).collect(Collectors.toList()));
    String triggerName = JobNamer.getTriggerName(JobNamer.getJobKey(report).getName());
    try {
        Trigger trigger = scheduler.getScheduler().getTrigger(new TriggerKey(triggerName, Scheduler.DEFAULT_GROUP));
        if (trigger != null) {
            reportTO.setLastExec(trigger.getPreviousFireTime());
            reportTO.setNextExec(trigger.getNextFireTime());
        }
    } catch (SchedulerException e) {
        LOG.warn("While trying to get to " + triggerName, e);
    }
    return reportTO;
}
Also used : TriggerKey(org.quartz.TriggerKey) Entity(org.apache.syncope.core.persistence.api.entity.Entity) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) ReportTO(org.apache.syncope.common.lib.to.ReportTO) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec)

Example 17 with TriggerKey

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

the class JobManagerImpl method unregisterJob.

private void unregisterJob(final String jobName) {
    try {
        scheduler.getScheduler().unscheduleJob(new TriggerKey(jobName, Scheduler.DEFAULT_GROUP));
        scheduler.getScheduler().deleteJob(new JobKey(jobName, Scheduler.DEFAULT_GROUP));
    } catch (SchedulerException e) {
        LOG.error("Could not remove job " + jobName, e);
    }
    if (ApplicationContextProvider.getBeanFactory().containsSingleton(jobName)) {
        ApplicationContextProvider.getBeanFactory().destroySingleton(jobName);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException)

Example 18 with TriggerKey

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

the class QuartzSessionValidationScheduler method disableSessionValidation.

public void disableSessionValidation() {
    if (log.isDebugEnabled()) {
        log.debug("Stopping Quartz session validation job...");
    }
    Scheduler scheduler;
    try {
        scheduler = getScheduler();
        if (scheduler == null) {
            if (log.isWarnEnabled()) {
                log.warn("getScheduler() method returned a null Quartz scheduler, which is unexpected.  Please check your configuration and/or implementation.  Returning quietly since there is no validation job to remove (scheduler does not exist).");
            }
            return;
        }
    } catch (SchedulerException e) {
        if (log.isWarnEnabled()) {
            log.warn("Unable to acquire Quartz Scheduler.  Ignoring and returning (already stopped?)", e);
        }
        return;
    }
    try {
        scheduler.unscheduleJob(new TriggerKey("SessionValidationJob", "DEFAULT"));
        if (log.isDebugEnabled())
            log.debug("Quartz session validation job stopped successfully.");
    } catch (SchedulerException e) {
        if (log.isDebugEnabled()) {
            log.debug("Could not cleanly remove SessionValidationJob from Quartz scheduler.  Ignoring and stopping.", e);
        }
    }
    this.enabled = false;
    if (this.schedulerImplicitlyCreated)
        try {
            scheduler.shutdown();
        } catch (SchedulerException e) {
            if (log.isWarnEnabled())
                log.warn("Unable to cleanly shutdown implicitly created Quartz Scheduler instance.", e);
        } finally {
            setScheduler(null);
            this.schedulerImplicitlyCreated = false;
        }
}
Also used : TriggerKey(org.quartz.TriggerKey) SchedulerException(org.quartz.SchedulerException) SessionValidationScheduler(org.apache.shiro.session.mgt.SessionValidationScheduler) Scheduler(org.quartz.Scheduler)

Example 19 with TriggerKey

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

the class ViteroModule method initCronJob.

private void initCronJob() {
    try {
        TriggerKey triggerKey = new TriggerKey("Vitero_Cleaner_Cron_Trigger", Scheduler.DEFAULT_GROUP);
        if (scheduler.getTrigger(triggerKey) == null) {
            // Create job with cron trigger configuration
            JobDetail jobDetail = newJob(ViteroZombieSlayerJob.class).withIdentity("Vitero_Cleaner_Cron_Job", Scheduler.DEFAULT_GROUP).build();
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.SECOND, 30);
            Trigger trigger = newTrigger().withIdentity("Vitero_Cleaner_Cron_Trigger").withSchedule(cronSchedule(cronExpression)).startAt(cal.getTime()).build();
            scheduler.scheduleJob(jobDetail, trigger);
        }
    } catch (Exception e) {
        log.error("Cannot start the Quartz Job which clean the Vitero rooms", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) Calendar(java.util.Calendar)

Example 20 with TriggerKey

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

the class MotechSchedulerServiceImpl method getScheduledJobTimingsWithPrefix.

/*
     * Loads all triggers and then loops over them to find the applicable trigger using string comparison. This
     * will work regardless of the jobId being cron or repeating.
     */
@Override
public List<DateTime> getScheduledJobTimingsWithPrefix(String subject, String externalJobIdPrefix, DateTime startDate, DateTime endDate) {
    JobId jobId = new CronJobId(subject, externalJobIdPrefix);
    List<Date> messageTimings = new ArrayList<>();
    try {
        List<TriggerKey> triggerKeys = new ArrayList<TriggerKey>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
        for (TriggerKey triggerKey : triggerKeys) {
            if (StringUtils.isNotEmpty(externalJobIdPrefix) && triggerKey.getName().contains(jobId.value())) {
                Trigger trigger = scheduler.getTrigger(triggerKey);
                messageTimings.addAll(TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate)));
            }
        }
    } catch (SchedulerException e) {
        throw new MotechSchedulerException(String.format("Can not get scheduled job timings given subject and externalJobIdPrefix for dates : %s %s %s %s %s", subject, externalJobIdPrefix, startDate.toString(), endDate.toString(), e.getMessage()), e);
    }
    return DateUtil.datesToDateTimes(messageTimings);
}
Also used : TriggerKey(org.quartz.TriggerKey) OperableTrigger(org.quartz.spi.OperableTrigger) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) SchedulerException(org.quartz.SchedulerException) CronJobId(org.motechproject.scheduler.contract.CronJobId) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) ArrayList(java.util.ArrayList) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) Date(java.util.Date)

Aggregations

TriggerKey (org.quartz.TriggerKey)116 Trigger (org.quartz.Trigger)49 SchedulerException (org.quartz.SchedulerException)34 JobKey (org.quartz.JobKey)33 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Scheduler (org.quartz.Scheduler)22 Test (org.junit.Test)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