Search in sources :

Example 1 with BaseCalendar

use of org.quartz.impl.calendar.BaseCalendar in project head by mifos.

the class BatchJobCatchUpIntegrationTest method testIncompleteTaskDelay.

@Test
public void testIncompleteTaskDelay() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask.xml");
    Scheduler scheduler = mifosScheduler.getScheduler();
    ProductStatus productStatusTask = new ProductStatus();
    productStatusTask.setJobExplorer(mifosScheduler.getBatchJobExplorer());
    productStatusTask.setJobLauncher(mifosScheduler.getBatchJobLauncher());
    productStatusTask.setJobLocator(mifosScheduler.getBatchJobLocator());
    productStatusTask.setJobRepository(mifosScheduler.getBatchJobRepository());
    String quartzJobName = "ProductStatusJob";
    String quartzTriggerName = "ProductStatusTrigger2";
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 10);
    Date previousFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 21);
    Date quartzFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 22);
    Date quartzNextFireTime = calendar.getTime();
    calendar.set(Calendar.SECOND, 20);
    Date quartzPrevFireTime = calendar.getTime();
    JobDetail jobDetail = scheduler.getJobDetail(quartzJobName, Scheduler.DEFAULT_GROUP);
    jobDetail.setJobDataMap(new JobDataMap());
    CronTrigger trigger = new CronTrigger(quartzTriggerName, Scheduler.DEFAULT_GROUP, quartzJobName, Scheduler.DEFAULT_GROUP, "* * * * * ?");
    trigger.setJobDataMap(new JobDataMap());
    TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(jobDetail, trigger, new BaseCalendar(), false, quartzFireTime, quartzFireTime, quartzPrevFireTime, quartzNextFireTime);
    JobExecutionContext jobExecutionContext = new JobExecutionContext(scheduler, triggerFiredBundle, productStatusTask);
    JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
    JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
    jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(previousFireTime.getTime()));
    Thread.sleep(1500);
    productStatusTask.catchUpMissedLaunches(jobLocator.getJob(jobName), jobExecutionContext);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 20);
    Assert.assertEquals(11, jobInstances.size());
    for (JobInstance jobInstance : jobInstances) {
        List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
        Assert.assertEquals(BatchStatus.COMPLETED, jobExecutions.get(0).getStatus());
        Assert.assertEquals(calendar.getTimeInMillis(), jobInstance.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY));
        calendar.roll(Calendar.SECOND, false);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) JobLauncher(org.springframework.batch.core.launch.JobLauncher) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobInstance(org.springframework.batch.core.JobInstance) Scheduler(org.quartz.Scheduler) Calendar(java.util.Calendar) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobLocator(org.springframework.batch.core.configuration.JobLocator) ProductStatus(org.mifos.framework.components.batchjobs.helpers.ProductStatus) TriggerFiredBundle(org.quartz.spi.TriggerFiredBundle) Date(java.util.Date) JobExecution(org.springframework.batch.core.JobExecution) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Test(org.junit.Test)

Example 2 with BaseCalendar

use of org.quartz.impl.calendar.BaseCalendar in project motech by motech.

the class MotechSchedulerServiceImpl method getScheduledJobTimingsWithPrefix.

/*
     * Loads all triggers and then loops over them to find the applicable trigger using string comparison. This
     * will work regardless of the jobId being cron or repeating.
     */
@Override
public List<DateTime> getScheduledJobTimingsWithPrefix(String subject, String externalJobIdPrefix, DateTime startDate, DateTime endDate) {
    JobId jobId = new CronJobId(subject, externalJobIdPrefix);
    List<Date> messageTimings = new ArrayList<>();
    try {
        List<TriggerKey> triggerKeys = new ArrayList<TriggerKey>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
        for (TriggerKey triggerKey : triggerKeys) {
            if (StringUtils.isNotEmpty(externalJobIdPrefix) && triggerKey.getName().contains(jobId.value())) {
                Trigger trigger = scheduler.getTrigger(triggerKey);
                messageTimings.addAll(TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate)));
            }
        }
    } catch (SchedulerException e) {
        throw new MotechSchedulerException(String.format("Can not get scheduled job timings given subject and externalJobIdPrefix for dates : %s %s %s %s %s", subject, externalJobIdPrefix, startDate.toString(), endDate.toString(), e.getMessage()), e);
    }
    return DateUtil.datesToDateTimes(messageTimings);
}
Also used : TriggerKey(org.quartz.TriggerKey) OperableTrigger(org.quartz.spi.OperableTrigger) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) SchedulerException(org.quartz.SchedulerException) CronJobId(org.motechproject.scheduler.contract.CronJobId) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) ArrayList(java.util.ArrayList) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) Date(java.util.Date)

Example 3 with BaseCalendar

use of org.quartz.impl.calendar.BaseCalendar in project kylo by Teradata.

the class AutowiringSpringBeanJobFactoryTest method testSetApplicationContext.

@Test
public void testSetApplicationContext() throws Exception {
    JobDetailImpl jobDetail = new JobDetailImpl();
    jobDetail.setJobClass(MockJob.class);
    TriggerFiredBundle bundle = new TriggerFiredBundle(jobDetail, Mockito.mock(OperableTrigger.class), new BaseCalendar(), true, new Date(), new Date(), new Date(), new Date());
    assertNotNull(factory.createJobInstance(bundle));
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) JobDetailImpl(org.quartz.impl.JobDetailImpl) TriggerFiredBundle(org.quartz.spi.TriggerFiredBundle) Date(java.util.Date) Test(org.junit.Test)

Example 4 with BaseCalendar

use of org.quartz.impl.calendar.BaseCalendar in project motech by motech.

the class MotechSchedulerServiceImpl method getScheduledJobTimings.

/*
     * Assumes that the externalJobId is non-repeating in nature. Thus the fetch is for jobId.value() and not
     * jobId.repeatingId()
     * Uses quartz API to fetch the exact triggers. Fast
     */
@Override
public List<DateTime> getScheduledJobTimings(String subject, String externalJobId, DateTime startDate, DateTime endDate) {
    JobId jobId = new CronJobId(subject, externalJobId);
    Trigger trigger;
    try {
        trigger = scheduler.getTrigger(triggerKey(jobId.value(), JOB_GROUP_NAME));
        return DateUtil.datesToDateTimes(TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate)));
    } catch (SchedulerException e) {
        throw new MotechSchedulerException(String.format("Can not get scheduled job timings given subject and externalJobId for dates : %s %s %s %s %s", subject, externalJobId, startDate.toString(), endDate.toString(), e.getMessage()), e);
    }
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) SchedulerException(org.quartz.SchedulerException) CronJobId(org.motechproject.scheduler.contract.CronJobId) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId)

Aggregations

BaseCalendar (org.quartz.impl.calendar.BaseCalendar)4 Date (java.util.Date)3 CronTrigger (org.quartz.CronTrigger)3 OperableTrigger (org.quartz.spi.OperableTrigger)3 Test (org.junit.Test)2 CronJobId (org.motechproject.scheduler.contract.CronJobId)2 JobId (org.motechproject.scheduler.contract.JobId)2 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)2 RepeatingPeriodJobId (org.motechproject.scheduler.contract.RepeatingPeriodJobId)2 RunOnceJobId (org.motechproject.scheduler.contract.RunOnceJobId)2 MotechSchedulerException (org.motechproject.scheduler.exception.MotechSchedulerException)2 SchedulerException (org.quartz.SchedulerException)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Trigger (org.quartz.Trigger)2 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)2 TriggerFiredBundle (org.quartz.spi.TriggerFiredBundle)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 ProductStatus (org.mifos.framework.components.batchjobs.helpers.ProductStatus)1 JobDataMap (org.quartz.JobDataMap)1