use of org.quartz.SimpleTrigger in project head by mifos.
the class BatchjobsServiceFacadeWebTier method getBatchjobs.
@Override
public List<BatchjobsDto> getBatchjobs(ServletContext context) throws TaskSystemException, FileNotFoundException, IOException, SchedulerException {
List<BatchjobsDto> batchjobs = new ArrayList<BatchjobsDto>();
MifosScheduler mifosScheduler = (MifosScheduler) context.getAttribute(MifosScheduler.class.getName());
Scheduler scheduler = mifosScheduler.getScheduler();
for (String groupName : scheduler.getJobGroupNames()) {
for (String jobName : scheduler.getJobNames(groupName)) {
Trigger[] triggers = scheduler.getTriggersOfJob(jobName, groupName);
Trigger trigger = triggers.length > 0 ? triggers[0] : null;
JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
if (trigger != null && jobDetail != null) {
Date nextFire = trigger.getNextFireTime() != null ? trigger.getNextFireTime() : new Date(0);
Date lastFire = mifosScheduler.getJobsPreviousRunTime(jobName);
Date lastSuccessfulRun = mifosScheduler.getJobsLastSuccessfulRunTime(jobName);
int priority = trigger.getPriority();
String frequency = "";
String taskType = "";
if (trigger instanceof CronTrigger) {
frequency = ((CronTrigger) trigger).getCronExpression();
taskType = CRON_TRIGGER;
}
if (trigger instanceof SimpleTrigger) {
frequency = Long.toString(((SimpleTrigger) trigger).getRepeatInterval());
taskType = SIMPLE_TRIGGER;
}
String previousRunStatus = mifosScheduler.getJobsPreviousRunStatus(jobName);
int triggerState = scheduler.getTriggerState(trigger.getName(), groupName);
String failDescription = mifosScheduler.getJobFailDescription(jobName);
batchjobs.add(new BatchjobsDto(jobName, frequency, taskType, priority, previousRunStatus, lastFire, lastSuccessfulRun, nextFire, triggerState, failDescription));
}
}
}
return batchjobs;
}
use of org.quartz.SimpleTrigger in project head by mifos.
the class MifosBatchJob method computeMissedJobLaunches.
@SuppressWarnings("unchecked")
public List<Date> computeMissedJobLaunches(Date from, Date to, Trigger trigger, boolean onDemandRun) throws Exception {
List<Date> missedLaunches = new LinkedList<Date>();
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = new CronTrigger();
cronTrigger.setStartTime(from);
cronTrigger.setNextFireTime(from);
String cronExpression = ((CronTrigger) trigger).getCronExpression();
try {
cronTrigger.setCronExpression(cronExpression);
} catch (ParseException pe) {
throw new Exception(pe);
}
List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(cronTrigger, null, from, to);
missedLaunches.addAll(computationOutcome);
missedLaunches.remove(0);
if (!onDemandRun && missedLaunches.size() > 0) {
missedLaunches.remove(missedLaunches.size() - 1);
}
} else if (trigger instanceof SimpleTrigger) {
SimpleTrigger simpleTrigger = new SimpleTrigger();
simpleTrigger.setStartTime(from);
simpleTrigger.setNextFireTime(from);
simpleTrigger.setRepeatInterval(((SimpleTrigger) trigger).getRepeatInterval());
simpleTrigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(simpleTrigger, null, from, to);
missedLaunches.addAll(computationOutcome);
missedLaunches.remove(0);
if (!onDemandRun && missedLaunches.size() > 0) {
missedLaunches.remove(missedLaunches.size() - 1);
}
}
return missedLaunches;
}
use of org.quartz.SimpleTrigger in project openhab1-addons by openhab.
the class MapDBPersistenceService method scheduleJob.
/**
* Schedules new quartz scheduler jobs for committing transactions and
* backing up the database
*/
private void scheduleJob() {
try {
Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
// schedule commit-job
JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build();
SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(commitInterval)).build();
sched.scheduleJob(job, trigger);
logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval);
} catch (SchedulerException e) {
logger.warn("Could not create Job: {}", e.getMessage());
}
}
use of org.quartz.SimpleTrigger in project openhab1-addons by openhab.
the class GCalPersistenceService method scheduleUploadJob.
/**
* Schedules new quartz scheduler job for uploading calendar entries to Google
*/
private void scheduleUploadJob() {
try {
scheduler = StdSchedulerFactory.getDefaultScheduler();
JobDetail job = newJob(SynchronizationJob.class).withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP).build();
SimpleTrigger trigger = newTrigger().withIdentity("Upload_GCal-Entries", GCAL_SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(uploadInterval)).build();
scheduler.scheduleJob(job, trigger);
logger.debug("Scheduled Google Calendar Upload-Job with interval '{}'", uploadInterval);
} catch (SchedulerException e) {
logger.warn("Could not create Google Calendar Upload-Job: {}", e.getMessage());
}
}
use of org.quartz.SimpleTrigger in project openhab1-addons by openhab.
the class Db4oPersistenceService method scheduleJob.
/**
* Schedules new quartz scheduler jobs for committing transactions and
* backing up the database
*/
private void scheduleJob() {
try {
Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
// schedule commit-job
JobDetail job = newJob(CommitJob.class).withIdentity("Commit_Transaction", SCHEDULER_GROUP).build();
SimpleTrigger trigger = newTrigger().withIdentity("Commit_Transaction", SCHEDULER_GROUP).withSchedule(repeatSecondlyForever(commitInterval)).build();
sched.scheduleJob(job, trigger);
logger.debug("Scheduled Commit-Job with interval {}sec.", commitInterval);
// schedule backup-job
JobDetail backupJob = newJob(BackupJob.class).withIdentity("Backup_DB", SCHEDULER_GROUP).build();
CronTrigger backupTrigger = newTrigger().withIdentity("Backup_DB", SCHEDULER_GROUP).withSchedule(CronScheduleBuilder.cronSchedule(backupInterval)).build();
sched.scheduleJob(backupJob, backupTrigger);
logger.debug("Scheduled Backup-Job with cron expression '{}'", backupInterval);
} catch (SchedulerException e) {
logger.warn("Could not create Job: {}", e.getMessage());
}
}
Aggregations