Search in sources :

Example 21 with TriggerKey

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

the class MotechSchedulerServiceImpl method unscheduleAllJobs.

@Override
public void unscheduleAllJobs(String jobIdPrefix) {
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Unscheduling jobs with prefix: ", jobIdPrefix);
        }
        List<TriggerKey> triggerKeys = new ArrayList<>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
        List<String> triggerNames = extractTriggerNames(triggerKeys);
        for (String triggerName : triggerNames) {
            if (StringUtils.isNotEmpty(jobIdPrefix) && triggerName.contains(jobIdPrefix)) {
                unscheduleJob(triggerName);
            }
        }
    } catch (SchedulerException e) {
        throw new MotechSchedulerException(String.format("Can not unschedule jobs given jobIdPrefix: %s %s", jobIdPrefix, e.getMessage()), e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException)

Example 22 with TriggerKey

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

the class SpringQuartzBundleIT method scheduleUnscheduleTest.

@Test
public void scheduleUnscheduleTest() throws SchedulerException {
    String uuidStr = UUID.randomUUID().toString();
    JobDetail job = newJob(MotechScheduledJob.class).withIdentity(uuidStr, groupName).build();
    job.getJobDataMap().put("eventType", "PillReminder");
    job.getJobDataMap().put("patientId", "001");
    SimpleTrigger trigger = newTrigger().withIdentity(triggerKey(uuidStr, groupName)).withSchedule(simpleSchedule()).startAt(new Date(new Date().getTime() + 3000)).build();
    Scheduler scheduler = factoryBean.getQuartzScheduler();
    scheduler.scheduleJob(job, trigger);
    List<JobKey> jobKeys = new ArrayList<>(scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)));
    List<String> jobNames = extractJobNames(jobKeys);
    assertEquals(1, jobNames.size());
    List<TriggerKey> triggerKeys = new ArrayList<>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName)));
    List<String> triggerNames = extractTriggerNames(triggerKeys);
    assertEquals(asList(uuidStr), triggerNames);
    scheduler.unscheduleJob(triggerKey(uuidStr, groupName));
    scheduler.deleteJob(jobKey(uuidStr, groupName));
    jobKeys = new ArrayList<>(scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)));
    jobNames = extractJobNames(jobKeys);
    assertEquals(0, jobNames.size());
    triggerKeys = new ArrayList<>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName)));
    triggerNames = extractTriggerNames(triggerKeys);
    assertEquals(0, triggerNames.size());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) SimpleTrigger(org.quartz.SimpleTrigger) Date(java.util.Date) Test(org.junit.Test)

Example 23 with TriggerKey

use of org.quartz.TriggerKey in project candlepin by candlepin.

the class PinsetterKernelTest method retriggerTest.

@Test
public void retriggerTest() throws Exception {
    pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
    String job = "CancelJobJob";
    TriggerKey key = new TriggerKey(job);
    Set<TriggerKey> keys = new HashSet<>();
    keys.add(key);
    when(sched.getTriggerKeys(any(GroupMatcher.class))).thenReturn(keys);
    pk.retriggerCronJob(job, CancelJobJob.class);
    ArgumentCaptor<Trigger> triggerCaptor = ArgumentCaptor.forClass(Trigger.class);
    verify(sched).rescheduleJob(eq(key), triggerCaptor.capture());
    Trigger capturedTrigger = triggerCaptor.getValue();
    TriggerKey keynow = capturedTrigger.getKey();
    String name = keynow.getName();
    assertTrue(capturedTrigger.getKey().getName().startsWith(job));
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) GroupMatcher(org.quartz.impl.matchers.GroupMatcher) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with TriggerKey

use of org.quartz.TriggerKey in project candlepin by candlepin.

the class PinsetterKernel method retriggerCronJob.

public void retriggerCronJob(String taskName, Class<? extends KingpinJob> jobClass) throws PinsetterException {
    Set<TriggerKey> cronTriggerKeys = null;
    try {
        cronTriggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(PinsetterKernel.CRON_GROUP));
        TriggerKey key = null;
        Iterator<TriggerKey> keysTrigger = cronTriggerKeys.iterator();
        // We should get only key per job. pick the first one and quit the loop
        while (key == null && keysTrigger.hasNext()) {
            TriggerKey current = keysTrigger.next();
            if (current.getName().contains(taskName)) {
                key = current;
            }
        }
        if (key != null) {
            String newJobName = taskName + "-" + Util.generateUUID();
            String schedule = getSchedule(jobClass.getName());
            if (schedule != null) {
                Trigger newTrigger = newTrigger().withIdentity(newJobName, CRON_GROUP).withSchedule(cronSchedule(schedule).withMisfireHandlingInstructionDoNothing()).build();
                scheduler.rescheduleJob(key, newTrigger);
            }
        }
    } catch (SchedulerException e) {
        throw new PinsetterException("There was a problem rescheduling cron job", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException)

Example 25 with TriggerKey

use of org.quartz.TriggerKey in project jbpm by kiegroup.

the class DeploymentsAwarePostgreSQLDelegate method selectMisfiredTriggersInState.

@Override
public List<TriggerKey> selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        List<String> deploymentIds = quartzUtils.getDeployments();
        ps = conn.prepareStatement(rtp(quartzUtils.misfiredTriggersQuery(deploymentIds)));
        ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts)));
        ps.setString(2, state);
        int index = 3;
        for (String deployment : deploymentIds) {
            ps.setString(index++, deployment);
        }
        rs = ps.executeQuery();
        LinkedList<TriggerKey> list = new LinkedList<TriggerKey>();
        while (rs.next()) {
            String triggerName = rs.getString(COL_TRIGGER_NAME);
            String groupName = rs.getString(COL_TRIGGER_GROUP);
            list.add(triggerKey(triggerName, groupName));
        }
        return list;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) LinkedList(java.util.LinkedList)

Aggregations

TriggerKey (org.quartz.TriggerKey)116 Trigger (org.quartz.Trigger)49 SchedulerException (org.quartz.SchedulerException)34 JobKey (org.quartz.JobKey)33 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Scheduler (org.quartz.Scheduler)22 Test (org.junit.Test)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4