Search in sources :

Example 26 with CronTrigger

use of org.quartz.CronTrigger in project ddf by codice.

the class WorkspaceQueryServiceImpl method setCronString.

/**
     * @param cronString cron string (must be non-null)
     */
@SuppressWarnings("unused")
public void setCronString(String cronString) {
    notNull(cronString, "cronString must be non-null");
    notNull(scheduler, "scheduler must be non-null");
    notNull(jobDetail, "jobDetail must be non-null");
    try {
        scheduler.deleteJob(jobDetail.getKey());
        LOGGER.debug("Scheduling job {}", jobDetail);
        CronTrigger trigger = newTrigger().withIdentity(TRIGGER_NAME).startNow().withSchedule(cronSchedule(cronString)).build();
        scheduler.scheduleJob(jobDetail, trigger);
        LOGGER.debug("Setting cron string : {}", cronString);
    } catch (SchedulerException e) {
        LOGGER.warn("Unable to update scheduler with cron string: cron=[{}]", cronString, e);
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException)

Example 27 with CronTrigger

use of org.quartz.CronTrigger in project engine by craftercms.

the class ConfigurationScriptJobResolverTest method testResolveJobs.

@Test
public void testResolveJobs() throws Exception {
    List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
    assertNotNull(jobContexts);
    assertEquals(2, jobContexts.size());
    JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
    CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/morejobs/testJob2.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
    jobDetail = (JobDetailImpl) jobContexts.get(1).getDetail();
    trigger = (CronTrigger) jobContexts.get(1).getTrigger();
    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetailImpl(org.quartz.impl.JobDetailImpl) JobContext(org.craftercms.engine.util.quartz.JobContext) Test(org.junit.Test)

Example 28 with CronTrigger

use of org.quartz.CronTrigger in project openhab1-addons by openhab.

the class MpdBinding method scheduleReconnect.

private void scheduleReconnect() {
    Scheduler sched;
    try {
        sched = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(ReconnectJob.class).withIdentity("Reconnect", MPD_SCHEDULER_GROUP).build();
        CronTrigger trigger = newTrigger().withIdentity("Reconnect", MPD_SCHEDULER_GROUP).withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?")).build();
        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled a daily reconnect of all MPDs");
    } catch (SchedulerException se) {
        logger.warn("Scheduling MPD reconnect failed", se);
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 29 with CronTrigger

use of org.quartz.CronTrigger in project openhab1-addons by openhab.

the class FritzboxBinding method updated.

/**
     * {@inheritDoc}
     */
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        String ip = Objects.toString(config.get("ip"), null);
        if (StringUtils.isNotBlank(ip)) {
            if (!ip.equals(FritzboxBinding.ip)) {
                // only do something if the ip has changed
                FritzboxBinding.ip = ip;
                conditionalDeActivate();
                // and thus blocks the monitor thread
                try {
                    Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
                    JobKey jobKey = jobKey("Reconnect", "FritzBox");
                    TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox");
                    if (sched.checkExists(jobKey)) {
                        logger.debug("Daily reconnection job already exists");
                    } else {
                        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronSchedule);
                        JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build();
                        CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
                        sched.scheduleJob(job, trigger);
                        logger.debug("Scheduled a daily reconnection to FritzBox on {}:{}", ip, MONITOR_PORT);
                    }
                } catch (SchedulerException e) {
                    logger.warn("Could not create daily reconnection job", e);
                }
            }
        }
        String password = Objects.toString(config.get("password"), null);
        if (StringUtils.isNotBlank(password)) {
            FritzboxBinding.password = password;
        }
        String username = Objects.toString(config.get("user"), null);
        if (StringUtils.isNotBlank(username)) {
            FritzboxBinding.username = username;
        }
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Example 30 with CronTrigger

use of org.quartz.CronTrigger in project openhab1-addons by openhab.

the class CallMonitor method setupReconnectJob.

/***
     * reset the connection to fbox periodically
     */
public void setupReconnectJob() {
    try {
        // String cronPattern = "0 0 0 * * ?"; //every day
        // String cronPattern = "0 * * * * ?"; //every minute
        // every 2 hrs
        String cronPattern = "0 0 0/2 * * ?";
        Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
        JobKey jobKey = jobKey("Reconnect", "FritzBox");
        TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox");
        if (sched.checkExists(jobKey)) {
            logger.debug("reconnection job already exists");
        } else {
            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronPattern);
            JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build();
            CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
            sched.scheduleJob(job, trigger);
            logger.debug("Scheduled reconnection job to FritzBox: {}", cronPattern);
        }
    } catch (SchedulerException e) {
        logger.warn("Could not create daily reconnection job", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler)

Aggregations

CronTrigger (org.quartz.CronTrigger)42 JobDetail (org.quartz.JobDetail)20 Test (org.junit.Test)17 Trigger (org.quartz.Trigger)14 SchedulerException (org.quartz.SchedulerException)13 Scheduler (org.quartz.Scheduler)12 SimpleTrigger (org.quartz.SimpleTrigger)11 TriggerKey (org.quartz.TriggerKey)7 JobKey (org.quartz.JobKey)5 Date (java.util.Date)4 CamelContext (org.apache.camel.CamelContext)4 JobDataMap (org.quartz.JobDataMap)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 CronScheduleBuilder (org.quartz.CronScheduleBuilder)2 JobExecutionException (org.quartz.JobExecutionException)2