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);
}
}
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());
}
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);
}
}
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;
}
}
}
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);
}
}
Aggregations