use of org.quartz.SimpleScheduleBuilder in project Dempsy by Dempsy.
the class OutputQuartzHelper method getSimpleTrigger.
/**
* Gets the simple trigger.
*
* @param timeUnit the time unit
* @param timeInterval the time interval
* @return the simple trigger
*/
public Trigger getSimpleTrigger(TimeUnit timeUnit, int timeInterval) {
SimpleScheduleBuilder simpleScheduleBuilder = null;
simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
switch(timeUnit) {
case MILLISECONDS:
simpleScheduleBuilder.withIntervalInMilliseconds(timeInterval).repeatForever();
break;
case SECONDS:
simpleScheduleBuilder.withIntervalInSeconds(timeInterval).repeatForever();
break;
case MINUTES:
simpleScheduleBuilder.withIntervalInMinutes(timeInterval).repeatForever();
break;
case HOURS:
simpleScheduleBuilder.withIntervalInHours(timeInterval).repeatForever();
break;
case DAYS:
simpleScheduleBuilder.withIntervalInHours(timeInterval * 24).repeatForever();
break;
default:
// default 1 sec
simpleScheduleBuilder.withIntervalInSeconds(1).repeatForever();
}
Trigger simpleTrigger = TriggerBuilder.newTrigger().withSchedule(simpleScheduleBuilder).build();
return simpleTrigger;
}
use of org.quartz.SimpleScheduleBuilder in project motech by motech.
the class MotechSchedulerServiceImpl method buildJobDetail.
private Trigger buildJobDetail(SchedulableJob schedulableJob, Date jobStartTime, Date jobEndTime, JobId jobId, JobDetail jobDetail, ScheduleBuilder scheduleBuilder) {
Trigger trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(scheduleBuilder).startAt(jobStartTime).endAt(jobEndTime).build();
DateTime now = now();
if (schedulableJob.isIgnorePastFiresAtStart() && newDateTime(jobStartTime).isBefore(now)) {
List<Date> pastTriggers = TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, null, jobStartTime, now.toDate());
if (pastTriggers.size() > 0) {
if (scheduleBuilder instanceof SimpleScheduleBuilder && ((RepeatingSchedulableJob) schedulableJob).getRepeatCount() != null) {
((SimpleScheduleBuilder) scheduleBuilder).withRepeatCount(((RepeatingSchedulableJob) schedulableJob).getRepeatCount() - pastTriggers.size());
}
Date newStartTime = getFirstTriggerInFuture(trigger, now);
trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(scheduleBuilder).startAt(newStartTime).endAt(jobEndTime).build();
}
}
return trigger;
}
use of org.quartz.SimpleScheduleBuilder in project motech by motech.
the class MotechSchedulerServiceImpl method scheduleRunOnceJob.
private void scheduleRunOnceJob(RunOnceSchedulableJob job, boolean update) {
logObjectIfNotNull(job);
validateRunOnceSchedulableJob(job);
MotechEvent motechEvent = job.getMotechEvent();
JobId jobId = new RunOnceJobId(motechEvent);
JobDetail jobDetail = newJob(MotechScheduledJob.class).withIdentity(jobId.value(), JOB_GROUP_NAME).build();
putMotechEventDataToJobDataMap(jobDetail.getJobDataMap(), motechEvent);
Map<String, Object> metadata = new HashMap<>();
metadata.put(UI_DEFINED, job.isUiDefined());
metadata.putAll(motechEvent.getMetadata());
jobDetail.getJobDataMap().put(EVENT_METADATA, metadata);
SimpleScheduleBuilder simpleSchedule = simpleSchedule().withRepeatCount(0).withIntervalInSeconds(0).withMisfireHandlingInstructionFireNow();
Trigger trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(simpleSchedule).startAt(DateUtil.toDate(job.getStartDate())).build();
scheduleJob(jobDetail, trigger, update);
}
use of org.quartz.SimpleScheduleBuilder in project Dempsy by Dempsy.
the class QuartzHelper method getSimpleTrigger.
/**
* Gets the simple trigger.
*
* @param timeUnit the time unit
* @param timeInterval the time interval
* @return the simple trigger
*/
public static Trigger getSimpleTrigger(final TimeUnit timeUnit, final int timeInterval, final boolean ignoreMisfires) {
SimpleScheduleBuilder simpleScheduleBuilder = null;
simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
switch(timeUnit) {
case MILLISECONDS:
simpleScheduleBuilder.withIntervalInMilliseconds(timeInterval).repeatForever();
break;
case SECONDS:
simpleScheduleBuilder.withIntervalInSeconds(timeInterval).repeatForever();
break;
case MINUTES:
simpleScheduleBuilder.withIntervalInMinutes(timeInterval).repeatForever();
break;
case HOURS:
simpleScheduleBuilder.withIntervalInHours(timeInterval).repeatForever();
break;
case DAYS:
simpleScheduleBuilder.withIntervalInHours(timeInterval * 24).repeatForever();
break;
default:
// default 1 sec
simpleScheduleBuilder.withIntervalInSeconds(1).repeatForever();
}
if (ignoreMisfires)
simpleScheduleBuilder.withMisfireHandlingInstructionIgnoreMisfires();
final Trigger simpleTrigger = TriggerBuilder.newTrigger().withSchedule(simpleScheduleBuilder).build();
return simpleTrigger;
}
use of org.quartz.SimpleScheduleBuilder in project Dempsy by Dempsy.
the class RelativeOutputSchedule method getSimpleTrigger.
/**
* Gets the simple trigger.
*
* @param timeUnit the time unit
* @param timeInterval the time interval
* @return the simple trigger
*/
private Trigger getSimpleTrigger(TimeUnit timeUnit, int timeInterval) {
SimpleScheduleBuilder simpleScheduleBuilder = null;
simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
switch(timeUnit) {
case MILLISECONDS:
simpleScheduleBuilder.withIntervalInMilliseconds(timeInterval).repeatForever();
break;
case SECONDS:
simpleScheduleBuilder.withIntervalInSeconds(timeInterval).repeatForever();
break;
case MINUTES:
simpleScheduleBuilder.withIntervalInMinutes(timeInterval).repeatForever();
break;
case HOURS:
simpleScheduleBuilder.withIntervalInHours(timeInterval).repeatForever();
break;
case DAYS:
simpleScheduleBuilder.withIntervalInHours(timeInterval * 24).repeatForever();
break;
default:
//default 1 sec
throw new RuntimeException("The " + RelativeOutputSchedule.class.getSimpleName() + " cannot handle a time unit of " + timeUnit);
}
Trigger simpleTrigger = TriggerBuilder.newTrigger().withSchedule(simpleScheduleBuilder).build();
return simpleTrigger;
}
Aggregations