Search in sources :

Example 6 with CronTriggerFactoryBean

use of org.springframework.scheduling.quartz.CronTriggerFactoryBean in project series-rest-api by 52North.

the class JobUtils method createCronTrigger.

default CronTriggerFactoryBean createCronTrigger(JobDetail jobDetail, String cronExpression, String triggerName) {
    getLogger().debug("createTrigger(jobDetail={}, cronExpression={}, triggerName={})", jobDetail.toString(), cronExpression, triggerName);
    // To fix an issue with time-based cron jobs
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
    factoryBean.setJobDetail(jobDetail);
    factoryBean.setCronExpression(cronExpression);
    factoryBean.setStartTime(calendar.getTime());
    factoryBean.setStartDelay(0L);
    factoryBean.setName(triggerName);
    factoryBean.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
    return factoryBean;
}
Also used : Calendar(java.util.Calendar) CronTriggerFactoryBean(org.springframework.scheduling.quartz.CronTriggerFactoryBean)

Example 7 with CronTriggerFactoryBean

use of org.springframework.scheduling.quartz.CronTriggerFactoryBean in project kylo by Teradata.

the class SimpleSchedulerSetup method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    MethodInvokingJobDetailFactoryBean jobDetailFactory = new MethodInvokingJobDetailFactoryBean();
    jobDetailFactory.setTargetObject(this.jobRunner);
    jobDetailFactory.setTargetMethod(this.targetMethod);
    jobDetailFactory.setName(this.jobName);
    jobDetailFactory.setGroup(this.groupName);
    jobDetailFactory.setConcurrent(concurrent);
    applicationContext.getAutowireCapableBeanFactory().initializeBean(jobDetailFactory, UUID.randomUUID().toString());
    CronTriggerFactoryBean triggerFactoryBean = new CronTriggerFactoryBean();
    triggerFactoryBean.setCronExpression(cronExpression);
    triggerFactoryBean.setJobDetail(jobDetailFactory.getObject());
    triggerFactoryBean.setGroup(this.groupName);
    if (this.jobName != null) {
        triggerFactoryBean.setName("trigger_" + this.jobName);
    }
    applicationContext.getAutowireCapableBeanFactory().initializeBean(triggerFactoryBean, UUID.randomUUID().toString());
    quartzScheduler.scheduleJob(jobDetailFactory, triggerFactoryBean);
}
Also used : CronTriggerFactoryBean(org.springframework.scheduling.quartz.CronTriggerFactoryBean) MethodInvokingJobDetailFactoryBean(org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean)

Aggregations

CronTriggerFactoryBean (org.springframework.scheduling.quartz.CronTriggerFactoryBean)7 MethodInvokingJobDetailFactoryBean (org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean)4 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 Job (com.weicoder.frame.quartz.Job)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 JobDetail (org.quartz.JobDetail)1 Trigger (org.quartz.Trigger)1 JobDetailFactoryBean (org.springframework.scheduling.quartz.JobDetailFactoryBean)1 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)1 SimpleTriggerFactoryBean (org.springframework.scheduling.quartz.SimpleTriggerFactoryBean)1