use of org.quartz.JobExecutionContext in project head by mifos.
the class BatchJobCatchUpIntegrationTest method testIncompleteTaskDelay.
@Test
public void testIncompleteTaskDelay() throws Exception {
mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask.xml");
Scheduler scheduler = mifosScheduler.getScheduler();
ProductStatus productStatusTask = new ProductStatus();
productStatusTask.setJobExplorer(mifosScheduler.getBatchJobExplorer());
productStatusTask.setJobLauncher(mifosScheduler.getBatchJobLauncher());
productStatusTask.setJobLocator(mifosScheduler.getBatchJobLocator());
productStatusTask.setJobRepository(mifosScheduler.getBatchJobRepository());
String quartzJobName = "ProductStatusJob";
String quartzTriggerName = "ProductStatusTrigger2";
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 10);
Date previousFireTime = calendar.getTime();
calendar.set(Calendar.SECOND, 21);
Date quartzFireTime = calendar.getTime();
calendar.set(Calendar.SECOND, 22);
Date quartzNextFireTime = calendar.getTime();
calendar.set(Calendar.SECOND, 20);
Date quartzPrevFireTime = calendar.getTime();
JobDetail jobDetail = scheduler.getJobDetail(quartzJobName, Scheduler.DEFAULT_GROUP);
jobDetail.setJobDataMap(new JobDataMap());
CronTrigger trigger = new CronTrigger(quartzTriggerName, Scheduler.DEFAULT_GROUP, quartzJobName, Scheduler.DEFAULT_GROUP, "* * * * * ?");
trigger.setJobDataMap(new JobDataMap());
TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(jobDetail, trigger, new BaseCalendar(), false, quartzFireTime, quartzFireTime, quartzPrevFireTime, quartzNextFireTime);
JobExecutionContext jobExecutionContext = new JobExecutionContext(scheduler, triggerFiredBundle, productStatusTask);
JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(previousFireTime.getTime()));
Thread.sleep(1500);
productStatusTask.catchUpMissedLaunches(jobLocator.getJob(jobName), jobExecutionContext);
JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 20);
Assert.assertEquals(11, jobInstances.size());
for (JobInstance jobInstance : jobInstances) {
List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecutions.get(0).getStatus());
Assert.assertEquals(calendar.getTimeInMillis(), jobInstance.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY));
calendar.roll(Calendar.SECOND, false);
}
}
use of org.quartz.JobExecutionContext 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
}
use of org.quartz.JobExecutionContext in project wso2-synapse by wso2.
the class QuartzTaskManager method isTaskRunning.
@Override
public boolean isTaskRunning(Object taskKey) {
if (!(taskKey instanceof JobKey)) {
return false;
}
try {
List<JobExecutionContext> currentJobs;
synchronized (lock) {
currentJobs = this.scheduler.getCurrentlyExecutingJobs();
}
JobKey currentJobKey;
for (JobExecutionContext jobCtx : currentJobs) {
currentJobKey = jobCtx.getJobDetail().getKey();
if (currentJobKey.compareTo((JobKey) taskKey) == 0) {
logger.warn("the job is already running");
return true;
}
}
} catch (SchedulerException e) {
return false;
}
return false;
}
use of org.quartz.JobExecutionContext in project xwiki-platform by xwiki.
the class AbstractJob method execute.
@Override
public final void execute(JobExecutionContext jobContext) throws JobExecutionException {
JobDataMap data = jobContext.getJobDetail().getJobDataMap();
// The XWiki context was saved in the Job execution data map. Get it as we'll retrieve
// the script to execute from it.
this.xcontext = (XWikiContext) data.get("context");
// Clone the XWikiContex to have a new one for each run
this.xcontext = this.xcontext.clone();
// Init execution context
Execution execution;
try {
ExecutionContextManager ecim = Utils.getComponent(ExecutionContextManager.class);
execution = Utils.getComponent(Execution.class);
ExecutionContext context = new ExecutionContext();
// Bridge with old XWiki Context, required for old code
this.xcontext.declareInExecutionContext(context);
ecim.initialize(context);
} catch (ExecutionContextException e) {
throw new JobExecutionException("Fail to initialize execution context", e);
}
try {
// Execute the job
executeJob(jobContext);
} finally {
// We must ensure we clean the ThreadLocal variables located in the Execution
// component as otherwise we will have a potential memory leak.
execution.removeContext();
}
}
use of org.quartz.JobExecutionContext in project incubator-gobblin by apache.
the class JobScheduler method shutDown.
@Override
protected void shutDown() throws Exception {
LOG.info("Stopping the job scheduler");
closer.close();
cancelRequested = true;
List<JobExecutionContext> currentExecutions = this.scheduler.getScheduler().getCurrentlyExecutingJobs();
for (JobExecutionContext jobExecutionContext : currentExecutions) {
try {
this.scheduler.getScheduler().interrupt(jobExecutionContext.getFireInstanceId());
} catch (UnableToInterruptJobException e) {
LOG.error("Failed to cancel job " + jobExecutionContext.getJobDetail().getKey(), e);
}
}
ExecutorsUtils.shutdownExecutorService(this.jobExecutor, Optional.of(LOG));
}
Aggregations