Search in sources :

Example 51 with SimpleTrigger

use of org.quartz.SimpleTrigger in project searchcode-server by boyter.

the class JobService method startDeleteJob.

/**
     * Starts a background job which deletes repositories from the database, index and checked out disk
     */
private void startDeleteJob() {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        // Setup the indexer which runs forever adding documents to be indexed
        JobDetail job = newJob(DeleteRepositoryJob.class).withIdentity("deletejob").build();
        SimpleTrigger trigger = newTrigger().withIdentity("deletejob").withSchedule(simpleSchedule().withIntervalInSeconds(1).repeatForever()).build();
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    } catch (SchedulerException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 52 with SimpleTrigger

use of org.quartz.SimpleTrigger in project searchcode-server by boyter.

the class JobService method startIndexFileRepoJobs.

/**
     * Creates a file repo indexer job which will pull from the file queue and index
     */
public void startIndexFileRepoJobs(String uniquename) {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        JobDetail job = newJob(IndexFileRepoJob.class).withIdentity("updateindex-file-" + uniquename).build();
        SimpleTrigger trigger = newTrigger().withIdentity("updateindex-file-" + uniquename).withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
        job.getJobDataMap().put("REPOLOCATIONS", this.REPOLOCATION);
        job.getJobDataMap().put("LOWMEMORY", this.LOWMEMORY);
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    } catch (SchedulerException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 53 with SimpleTrigger

use of org.quartz.SimpleTrigger in project iaf by ibissource.

the class SchedulerAdapter method triggerToXmlBuilder.

public XmlBuilder triggerToXmlBuilder(Scheduler theScheduler, String triggerName, String groupName) {
    XmlBuilder xbRoot = new XmlBuilder("triggerDetail");
    try {
        Trigger trigger = theScheduler.getTrigger(triggerName, groupName);
        xbRoot.addAttribute("fullName", trigger.getFullName());
        xbRoot.addAttribute("triggerName", trigger.getName());
        xbRoot.addAttribute("triggerGroup", trigger.getGroup());
        String cn = trigger.getCalendarName();
        xbRoot.addAttribute("calendarName", (cn == null ? "none" : cn));
        Date date;
        try {
            date = trigger.getEndTime();
            xbRoot.addAttribute("endTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getFinalFireTime();
            xbRoot.addAttribute("finalFireTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getPreviousFireTime();
            xbRoot.addAttribute("previousFireTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getNextFireTime();
            xbRoot.addAttribute("nextFireTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        try {
            date = trigger.getStartTime();
            xbRoot.addAttribute("startTime", (null == date ? "" : DateUtils.format(date, DateUtils.FORMAT_GENERICDATETIME)));
        } catch (Exception e) {
            log.debug(e);
        }
        ;
        xbRoot.addAttribute("misfireInstruction", Integer.toString(trigger.getMisfireInstruction()));
        if (trigger instanceof CronTrigger) {
            xbRoot.addAttribute("triggerType", "cron");
            xbRoot.addAttribute("cronExpression", ((CronTrigger) trigger).getCronExpression());
        } else if (trigger instanceof SimpleTrigger) {
            xbRoot.addAttribute("triggerType", "simple");
            xbRoot.addAttribute("repeatInterval", ((SimpleTrigger) trigger).getRepeatInterval());
        } else {
            xbRoot.addAttribute("triggerType", "unknown");
        }
        xbRoot.addAttribute("jobGroup", trigger.getJobGroup());
        xbRoot.addAttribute("jobName", trigger.getJobName());
        xbRoot.addAttribute("isVolatile", (trigger.isVolatile() ? "True" : "False"));
    } catch (SchedulerException se) {
        log.error(se);
    }
    return xbRoot;
}
Also used : CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) SimpleTrigger(org.quartz.SimpleTrigger) Date(java.util.Date) SchedulerException(org.quartz.SchedulerException)

Example 54 with SimpleTrigger

use of org.quartz.SimpleTrigger in project motech by motech.

the class CronJobSimpleExpressionBuilderTest method shouldScheduleJobEverySevenDays.

@Test
public void shouldScheduleJobEverySevenDays() {
    SimpleTrigger trigger = newTrigger().withIdentity(triggerKey("triggerName", "groupName")).startNow().withSchedule(simpleSchedule().withIntervalInHours(7 * 24).repeatForever()).build();
    LocalDate today = DateUtil.today();
    Date yesterday = today.plusDays(-1).toDate();
    Date firstFireTime = trigger.getFireTimeAfter(yesterday);
    Date secondFireTime = trigger.getFireTimeAfter(firstFireTime);
    Date thirdFireTime = trigger.getFireTimeAfter(secondFireTime);
    assertEquals(Duration.standardDays(7).getMillis(), secondFireTime.getTime() - firstFireTime.getTime());
    assertEquals(Duration.standardDays(7).getMillis(), thirdFireTime.getTime() - secondFireTime.getTime());
}
Also used : SimpleTrigger(org.quartz.SimpleTrigger) LocalDate(org.joda.time.LocalDate) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) Test(org.junit.Test)

Example 55 with SimpleTrigger

use of org.quartz.SimpleTrigger in project motech by motech.

the class SchedulableJobBuilder method buildRepeatingSchedulableJob.

private static SchedulableJob buildRepeatingSchedulableJob(Trigger trigger, JobDataMap dataMap) {
    RepeatingSchedulableJob job = new RepeatingSchedulableJob();
    long interval;
    if (trigger instanceof CalendarIntervalTrigger) {
        CalendarIntervalTrigger calendarTrigger = (CalendarIntervalTrigger) trigger;
        interval = calendarTrigger.getRepeatInterval();
    } else {
        SimpleTrigger simpleTrigger = (SimpleTrigger) trigger;
        job.setRepeatCount(simpleTrigger.getRepeatCount());
        interval = simpleTrigger.getRepeatInterval() / SECOND;
    }
    job.setEndDate(getEndDate(trigger));
    job.setRepeatIntervalInSeconds((int) interval);
    job.setIgnorePastFiresAtStart(dataMap.getBoolean(IGNORE_PAST_FIRES_AT_START));
    job.setUseOriginalFireTimeAfterMisfire(dataMap.getBoolean(USE_ORIGINAL_FIRE_TIME_AFTER_MISFIRE));
    return job;
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) SimpleTrigger(org.quartz.SimpleTrigger) CalendarIntervalTrigger(org.quartz.CalendarIntervalTrigger)

Aggregations

SimpleTrigger (org.quartz.SimpleTrigger)75 CronTrigger (org.quartz.CronTrigger)27 SchedulerException (org.quartz.SchedulerException)27 JobDetail (org.quartz.JobDetail)24 Date (java.util.Date)22 Scheduler (org.quartz.Scheduler)21 Trigger (org.quartz.Trigger)20 Test (org.junit.Test)11 JobDataMap (org.quartz.JobDataMap)11 ArrayList (java.util.ArrayList)9 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 SimpleDateFormat (java.text.SimpleDateFormat)5 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)5 DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)5 TriggerKey (org.quartz.TriggerKey)5 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)4 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)4