use of org.pentaho.platform.api.scheduler2.JobTrigger in project pentaho-platform by pentaho.
the class BlockoutManagerUtil method getFireTimes.
public static List<Date> getFireTimes(IJobTrigger jobTrigger, IScheduler scheduler) {
// Determines the maximum amount of fire times allowed to be calculated
int n = 1000;
Date startDate = new Date(System.currentTimeMillis());
Date endDate = new Date(startDate.getTime() + 4 * TIME.YEAR.time);
// Quartz Triggers
if (scheduler instanceof QuartzScheduler) {
try {
List<Date> dates = new ArrayList<Date>();
boolean endDateIsNull = jobTrigger.getEndTime() == null;
// $NON-NLS-1$ //$NON-NLS-2$
Trigger trigger = QuartzScheduler.createQuartzTrigger(jobTrigger, new QuartzJobKey("test", "test"));
// add previous trigger (it might be currently active)
// $NON-NLS-1$;
IBlockoutManager manager = PentahoSystem.get(IBlockoutManager.class, "IBlockoutManager", null);
if (manager != null) {
List<Job> blockouts = manager.getBlockOutJobs();
for (Job blockout : blockouts) {
if (blockout.getLastRun() != null) {
dates.add(blockout.getLastRun());
}
}
}
for (int i = 0; i < n; i++) {
Date nextFireTime = trigger.getFireTimeAfter(startDate);
if ((nextFireTime == null) || (nextFireTime.after(endDate) || (!endDateIsNull && nextFireTime.after(jobTrigger.getEndTime())))) {
break;
}
dates.add(nextFireTime);
startDate = nextFireTime;
}
return dates;
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
throw new RuntimeException(// $NON-NLS-1$
"Can not calculate fire times for unsupported Scheduler Type: " + scheduler.getClass().getSimpleName());
}
use of org.pentaho.platform.api.scheduler2.JobTrigger in project pentaho-platform by pentaho.
the class RepositoryCleanerSystemListener method rescheduleIfNecessary.
private void rescheduleIfNecessary(IScheduler scheduler, List<Job> jobs) throws SchedulerException {
JobTrigger trigger = findJobTrigger();
if (trigger == null) {
return;
}
List<Job> matched = new ArrayList<Job>(jobs.size());
for (Job job : jobs) {
JobTrigger tr = job.getJobTrigger();
// unfortunately, JobTrigger does not override equals
if (trigger.getClass() != tr.getClass()) {
logger.info("Removing job with id: " + job.getJobId());
scheduler.removeJob(job.getJobId());
} else {
matched.add(job);
}
}
if (matched.isEmpty()) {
logger.info("Need to re-schedule job");
scheduleJob(scheduler);
}
}
use of org.pentaho.platform.api.scheduler2.JobTrigger in project pentaho-platform by pentaho.
the class RepositoryCleanerSystemListener method scheduleJob.
private void scheduleJob(IScheduler scheduler) throws SchedulerException {
JobTrigger trigger = findJobTrigger();
if (trigger != null) {
logger.info("Creating new job with trigger: " + trigger);
scheduler.createJob(RepositoryGcJob.JOB_NAME, RepositoryGcJob.class, null, trigger);
}
}
use of org.pentaho.platform.api.scheduler2.JobTrigger in project pentaho-platform by pentaho.
the class EmbeddedVersionCheckSystemListener method scheduleJob.
protected void scheduleJob(final int versionRequestFlags, final int repeatSeconds) throws Exception {
// $NON-NLS-1$
IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
deleteJobIfNecessary();
Map<String, Serializable> parms = new HashMap<String, Serializable>();
parms.put(VersionCheckerAction.VERSION_REQUEST_FLAGS, new Integer(versionRequestFlags));
JobTrigger trigger = new SimpleJobTrigger(new Date(), null, -1, repeatSeconds);
scheduler.createJob(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME, VersionCheckerAction.class, parms, trigger);
}
use of org.pentaho.platform.api.scheduler2.JobTrigger in project pentaho-platform by pentaho.
the class DefaultSchedulerService method createJob.
private String createJob(String jobName, Map<String, ParamValue> jobParams, JobTrigger trigger) throws SchedulerException {
// $NON-NLS-1$
logger.debug("Creating job with schedule " + trigger.toString());
Job job = null;
try {
// $NON-NLS-1$
IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
Map<String, Serializable> properJobParams = toProperMap(jobParams);
scheduler.validateJobParams(properJobParams);
job = scheduler.createJob(jobName, getDefaultActionId(), properJobParams, trigger);
} catch (SchedulerException e) {
// temporary error logging.. this needs to become an aspect
logger.error(e.getMessage(), e);
throw e;
}
return job.getJobId();
}
Aggregations