use of org.quartz.JobDetail in project cdap by caskdata.
the class DatasetBasedTimeScheduleStoreTest method testJobKeyDeletion.
private void testJobKeyDeletion(String version) throws Exception {
schedulerSetup(true);
String jobGroup = "jg";
JobDetail jobDetail = getJobDetail(jobGroup, "job1", version);
JobDetail versionLessJobDetail = getJobDetail(jobGroup, "job1", null);
scheduler.addJob(versionLessJobDetail, true);
scheduler.addJob(jobDetail, true);
schedulerTearDown();
schedulerSetup(true);
Set<JobKey> keys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup));
if (version.equals(ApplicationId.DEFAULT_VERSION)) {
Assert.assertEquals(1, keys.size());
Assert.assertTrue(scheduler.deleteJob(jobDetail.getKey()));
} else {
Assert.assertEquals(2, keys.size());
Assert.assertTrue(scheduler.deleteJob(jobDetail.getKey()));
Assert.assertTrue(scheduler.deleteJob(versionLessJobDetail.getKey()));
}
schedulerTearDown();
schedulerSetup(true);
Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup));
Assert.assertEquals(0, jobKeys.size());
schedulerTearDown();
}
use of org.quartz.JobDetail in project searchcode-server by boyter.
the class JobService method startIndexerJob.
private void startIndexerJob() throws SchedulerException {
Scheduler scheduler = Singleton.getScheduler();
// Setup the indexer which runs forever indexing
JobDetail job = newJob(IndexDocumentsJob.class).withIdentity("indexerjob").build();
SimpleTrigger trigger = newTrigger().withIdentity("indexerjob").withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
}
use of org.quartz.JobDetail in project searchcode-server by boyter.
the class JobService method startIndexSvnRepoJobs.
/**
* Creates a svn repo indexer job which will pull from the list of git repositories and start
* indexing them
*/
public void startIndexSvnRepoJobs(String uniquename) {
try {
Scheduler scheduler = Singleton.getScheduler();
JobDetail job = newJob(IndexSvnRepoJob.class).withIdentity("updateindex-svn-" + uniquename).build();
SimpleTrigger trigger = newTrigger().withIdentity("updateindex-svn-" + 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());
}
}
use of org.quartz.JobDetail in project opennms by OpenNMS.
the class Statsd method scheduleReport.
private void scheduleReport(ReportDefinition reportDef) throws ClassNotFoundException, NoSuchMethodException, ParseException, SchedulerException, Exception {
// this is most likely reentrant since the method is private and called from start via plural version.
synchronized (m_scheduler) {
MethodInvokingJobDetailFactoryBean jobFactory = new MethodInvokingJobDetailFactoryBean();
jobFactory.setTargetObject(this);
jobFactory.setTargetMethod("runReport");
jobFactory.setArguments(new Object[] { reportDef });
jobFactory.setConcurrent(false);
jobFactory.setBeanName(reportDef.getDescription());
jobFactory.afterPropertiesSet();
JobDetail jobDetail = (JobDetail) jobFactory.getObject();
CronTriggerFactoryBean cronReportTrigger = new CronTriggerFactoryBean();
cronReportTrigger.setBeanName(reportDef.getDescription());
cronReportTrigger.setJobDetail(jobDetail);
cronReportTrigger.setCronExpression(reportDef.getCronExpression());
cronReportTrigger.afterPropertiesSet();
m_scheduler.scheduleJob(jobDetail, cronReportTrigger.getObject());
LOG.debug("Schedule report {}", cronReportTrigger);
}
}
use of org.quartz.JobDetail in project opennms by OpenNMS.
the class ImportSchedulerIT method createJobAndVerifyImportJobFactoryIsRegistered.
@Test
public void createJobAndVerifyImportJobFactoryIsRegistered() throws SchedulerException, InterruptedException {
RequisitionDef def = m_dao.getDefs().get(0);
JobDetail detail = new JobDetailImpl("test", ImportScheduler.JOB_GROUP, ImportJob.class, false, false);
detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource().orElse(null));
detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
class MyBoolWrapper {
volatile Boolean m_called = false;
public Boolean getCalled() {
return m_called;
}
public void setCalled(Boolean called) {
m_called = called;
}
}
final MyBoolWrapper callTracker = new MyBoolWrapper();
m_importScheduler.getScheduler().getListenerManager().addTriggerListener(new TriggerListener() {
@Override
public String getName() {
return "TestTriggerListener";
}
@Override
public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
LOG.info("triggerComplete called on trigger listener");
callTracker.setCalled(true);
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext context) {
LOG.info("triggerFired called on trigger listener");
Job jobInstance = context.getJobInstance();
if (jobInstance instanceof ImportJob) {
Assert.assertNotNull(((ImportJob) jobInstance).getProvisioner());
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.URL));
Assert.assertEquals("dns://localhost/localhost", context.getJobDetail().getJobDataMap().get(ImportJob.URL));
Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.RESCAN_EXISTING));
Assert.assertEquals("dbonly", context.getJobDetail().getJobDataMap().get(ImportJob.RESCAN_EXISTING));
}
callTracker.setCalled(true);
}
@Override
public void triggerMisfired(Trigger trigger) {
LOG.info("triggerMisFired called on trigger listener");
callTracker.setCalled(true);
}
@Override
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
LOG.info("vetoJobExecution called on trigger listener");
callTracker.setCalled(true);
return false;
}
});
Calendar testCal = Calendar.getInstance();
testCal.add(Calendar.SECOND, 5);
SimpleTriggerImpl trigger = new SimpleTriggerImpl("test", ImportScheduler.JOB_GROUP, testCal.getTime());
m_importScheduler.getScheduler().scheduleJob(detail, trigger);
m_importScheduler.start();
int callCheck = 0;
while (!callTracker.getCalled() && callCheck++ < 2) {
Thread.sleep(5000);
}
// TODO: need to fix the interrupted exception that occurs in the provisioner
}
Aggregations