Search in sources :

Example 1 with AnnualCalendar

use of org.quartz.impl.calendar.AnnualCalendar in project dq-easy-cloud by dq-open-cloud.

the class EcTaskSchedulerConfig method getAnnualCalendar.

private AnnualCalendar getAnnualCalendar() {
    AnnualCalendar holidays = new AnnualCalendar();
    Calendar calendar = new GregorianCalendar(2018, 5, 11);
    holidays.setDayExcluded(calendar, true);
    return holidays;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar)

Example 2 with AnnualCalendar

use of org.quartz.impl.calendar.AnnualCalendar in project dq-easy-cloud by dq-open-cloud.

the class CalendarExample method run.

public void run() throws Exception {
    final Logger log = LoggerFactory.getLogger(CalendarExample.class);
    log.info("------- Initializing ----------------------");
    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();
    log.info("------- Initialization Complete -----------");
    log.info("------- Scheduling Jobs -------------------");
    // Add the holiday calendar to the schedule
    AnnualCalendar holidays = new AnnualCalendar();
    // fourth of July (July 4)
    Calendar fourthOfJuly = new GregorianCalendar(2018, 6, 14);
    holidays.setDayExcluded(fourthOfJuly, true);
    // halloween (Oct 31)
    Calendar halloween = new GregorianCalendar(2005, 9, 31);
    holidays.setDayExcluded(halloween, true);
    // christmas (Dec 25)
    Calendar christmas = new GregorianCalendar(2005, 11, 25);
    holidays.setDayExcluded(christmas, true);
    // tell the schedule about our holiday calendar
    sched.addCalendar("holidays", holidays, false, false);
    // schedule a job to run hourly, starting on halloween
    // at 10 am
    Date runDate = dateOf(0, 0, 10, 31, 10);
    runDate = new Date();
    JobDetail job = newJob(SimpleJob.class).withIdentity("job1", "group1").build();
    SimpleTrigger trigger = newTrigger().withIdentity("trigger1", "group1").startAt(runDate).withSchedule(SimpleScheduleBuilder.repeatSecondlyForever()).modifiedByCalendar("holidays").build();
    // schedule the job and print the first run date
    Date firstRunTime = sched.scheduleJob(job, trigger);
    // print out the first execution date.
    // Note: Since Halloween (Oct 31) is a holiday, then
    // we will not run until the next day! (Nov 1)
    log.info(job.getKey() + " will run at: " + firstRunTime + " and repeat: " + trigger.getRepeatCount() + " times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
    // All of the jobs have been added to the scheduler, but none of the jobs
    // will run until the scheduler has been started
    log.info("------- Starting Scheduler ----------------");
    sched.start();
    // wait 5 seconds:
    // note: nothing will run
    log.info("------- Waiting 30 seconds... --------------");
    try {
        // wait 30 seconds to show jobs
        Thread.sleep(5L * 1000L);
    // executing...
    } catch (Exception e) {
    // 
    }
    // shut down the scheduler
    log.info("------- Shutting Down ---------------------");
    sched.shutdown(true);
    log.info("------- Shutdown Complete -----------------");
    SchedulerMetaData metaData = sched.getMetaData();
    log.info("Executed " + metaData.getNumberOfJobsExecuted() + " jobs.");
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar) GregorianCalendar(java.util.GregorianCalendar) Logger(org.slf4j.Logger) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar) Date(java.util.Date) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 3 with AnnualCalendar

use of org.quartz.impl.calendar.AnnualCalendar in project dq-easy-cloud by dq-open-cloud.

the class MyCronTrigger method main.

public static void main(String[] args) throws SchedulerException {
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    Scheduler scheduler = schedulerFactory.getScheduler();
    AnnualCalendar holidays = new AnnualCalendar();
    Calendar calendar = new GregorianCalendar(2018, 5, 13);
    holidays.setDayExcluded(calendar, true);
    scheduler.addCalendar("holidays", holidays, false, false);
    JobDetail jobDetail = JobBuilder.newJob(MyCronJob.class).withIdentity("cron", "crongroup").build();
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity("cronTrigger", "cronTriggerGroup").withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ? ")).modifiedByCalendar("holidays").build();
    scheduler.scheduleJob(jobDetail, trigger);
    scheduler.start();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar) GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 4 with AnnualCalendar

use of org.quartz.impl.calendar.AnnualCalendar in project dq-easy-cloud by dq-open-cloud.

the class EcTaskSchedulerManager method buildCalendar.

private Trigger buildCalendar(final EcTaskSchedulerDTO taskSchedulerDTO, final Trigger trigger) throws SchedulerException {
    logger.info("holidayName:" + taskSchedulerDTO.getHolidayName());
    logger.info("holidays:" + taskSchedulerDTO.getHolidayDTOs());
    if (taskSchedulerDTO.getHolidayName() != null && EcCollectionsUtils.isNotEmpty(taskSchedulerDTO.getHolidayDTOs())) {
        AnnualCalendar holidays = new AnnualCalendar();
        for (EcHolidayDTO holidayDTO : taskSchedulerDTO.getHolidayDTOs()) {
            Calendar calendar = new GregorianCalendar(holidayDTO.getYear(), holidayDTO.getMonth() - 1, holidayDTO.getDay());
            holidays.setDayExcluded(calendar, true);
        }
        scheduler.addCalendar(taskSchedulerDTO.getHolidayName(), holidays, true, true);
        return trigger.getTriggerBuilder().modifiedByCalendar(taskSchedulerDTO.getHolidayName()).build();
    } else {
        return trigger.getTriggerBuilder().modifiedByCalendar(null).build();
    }
// return trigger;
}
Also used : EcHolidayDTO(com.easy.cloud.core.worker.scheduler.pojo.dto.EcHolidayDTO) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar) GregorianCalendar(java.util.GregorianCalendar) AnnualCalendar(org.quartz.impl.calendar.AnnualCalendar)

Aggregations

Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 AnnualCalendar (org.quartz.impl.calendar.AnnualCalendar)4 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)2 EcHolidayDTO (com.easy.cloud.core.worker.scheduler.pojo.dto.EcHolidayDTO)1 Date (java.util.Date)1 Logger (org.slf4j.Logger)1