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);
}
}
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());
}
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));
}
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);
}
}
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);
}
}
Aggregations