Search in sources :

Example 6 with JobDetail

use of org.quartz.JobDetail in project jmxtrans by jmxtrans.

the class JmxTransformer method deleteAllJobs.

private void deleteAllJobs() throws Exception {
    List<JobDetail> allJobs = new ArrayList<>();
    String[] jobGroups = serverScheduler.getJobGroupNames();
    for (String jobGroup : jobGroups) {
        String[] jobNames = serverScheduler.getJobNames(jobGroup);
        for (String jobName : jobNames) {
            allJobs.add(serverScheduler.getJobDetail(jobName, jobGroup));
        }
    }
    for (JobDetail jd : allJobs) {
        serverScheduler.deleteJob(jd.getName(), jd.getGroup());
        if (log.isDebugEnabled()) {
            log.debug("Deleted scheduled job: " + jd.getName() + " group: " + jd.getGroup());
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) ArrayList(java.util.ArrayList)

Example 7 with JobDetail

use of org.quartz.JobDetail in project pinot by linkedin.

the class AlertJobScheduler method scheduleJob.

private void scheduleJob(JobContext jobContext, EmailConfigurationDTO alertConfig) {
    LOG.info("Starting {}", jobContext.getJobName());
    String triggerKey = String.format("alert_scheduler_trigger_%d", alertConfig.getId());
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(CronScheduleBuilder.cronSchedule(alertConfig.getCron())).build();
    String jobKey = jobContext.getJobName();
    JobDetail job = JobBuilder.newJob(AlertJobRunner.class).withIdentity(jobKey).build();
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_CONTEXT, jobContext);
    try {
        quartzScheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error("Exception while scheduling alert job", e);
    }
    LOG.info("Started {}: {}", jobKey, alertConfig);
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException)

Example 8 with JobDetail

use of org.quartz.JobDetail in project pinot by linkedin.

the class AlertJobSchedulerV2 method scheduleJob.

private void scheduleJob(JobContext jobContext, AlertConfigDTO alertConfig) {
    LOG.info("Starting {}", jobContext.getJobName());
    String triggerKey = String.format("alert_scheduler_trigger_%d", alertConfig.getId());
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(CronScheduleBuilder.cronSchedule(alertConfig.getCronExpression())).build();
    String jobKey = jobContext.getJobName();
    JobDetail job = JobBuilder.newJob(AlertJobRunnerV2.class).withIdentity(jobKey).build();
    job.getJobDataMap().put(AlertJobRunnerV2.ALERT_JOB_CONTEXT_V2, jobContext);
    try {
        quartzScheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error("Exception while scheduling alert job", e);
    }
    LOG.info("Started {}: {}", jobKey, alertConfig);
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException)

Example 9 with JobDetail

use of org.quartz.JobDetail 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;
}
Also used : CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) ArrayList(java.util.ArrayList) BatchjobsDto(org.mifos.application.admin.servicefacade.BatchjobsDto) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) Date(java.util.Date) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger)

Example 10 with JobDetail

use of org.quartz.JobDetail 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)

Aggregations

JobDetail (org.quartz.JobDetail)122 SchedulerException (org.quartz.SchedulerException)56 Trigger (org.quartz.Trigger)47 Scheduler (org.quartz.Scheduler)33 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)25 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)21 JobDataMap (org.quartz.JobDataMap)18 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 IOException (java.io.IOException)5 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4