use of org.springframework.batch.core.JobExecution in project head by mifos.
the class MifosBatchJob method launchJob.
/**
* A method responsible for the actual launch of the Spring Batch job.
* @param job Job class
* @param jobParameters Job parameters
* @return Batch computation status
* @throws BatchJobException when something goes wrong
*/
private BatchStatus launchJob(Job job, JobParameters jobParameters) throws BatchJobException {
BatchStatus exitStatus = BatchStatus.UNKNOWN;
JobExecution jobExecution = null;
try {
batchJobStarted();
requiresExclusiveAccess();
jobExecution = jobLauncher.run(job, jobParameters);
exitStatus = jobExecution.getStatus();
} catch (JobInstanceAlreadyCompleteException jiace) {
exitStatus = BatchStatus.COMPLETED;
return exitStatus;
} catch (Exception ex) {
throw new BatchJobException(ex);
} finally {
batchJobFinished();
}
return exitStatus;
}
use of org.springframework.batch.core.JobExecution in project head by mifos.
the class MifosScheduler method getJobFailDescription.
public String getJobFailDescription(String jobName) {
String failDescription = null;
JobExplorer explorer = getBatchJobExplorer();
List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
if (jobInstances.size() > 0) {
List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstances.get(0));
if (jobExecutions.size() > 0) {
Collection<StepExecution> steps = jobExecutions.get(0).getStepExecutions();
if (steps.size() > 0) {
StepExecution step = steps.iterator().next();
if (!step.getExitStatus().getExitDescription().isEmpty()) {
failDescription = step.getExitStatus().getExitDescription();
}
}
}
}
return failDescription;
}
use of org.springframework.batch.core.JobExecution in project head by mifos.
the class MifosScheduler method getJobsLastSuccessfulRunTime.
public Date getJobsLastSuccessfulRunTime(String jobName) {
JobExplorer explorer = getBatchJobExplorer();
List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 100);
for (JobInstance job : jobInstances) {
for (JobExecution execution : explorer.getJobExecutions(job)) {
if (BatchStatus.COMPLETED.equals(execution.getStatus())) {
long executionTimeInMillis = job.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY);
return new Date(executionTimeInMillis);
}
}
}
return new Date(0);
}
use of org.springframework.batch.core.JobExecution 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.springframework.batch.core.JobExecution in project head by mifos.
the class BatchJobCatchUpIntegrationTest method testFailureDuringIncompleteTaskHandling.
@Test
public void testFailureDuringIncompleteTaskHandling() throws Exception {
mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/catchUpTask3.xml");
JobLauncher jobLauncher = mifosScheduler.getBatchJobLauncher();
JobLocator jobLocator = mifosScheduler.getBatchJobLocator();
for (int i = 0; i < 3; i++) {
jobLauncher.run(jobLocator.getJob(jobName), MifosBatchJob.createJobParameters(new Date().getTime()));
Thread.sleep(5000);
}
JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
Assert.assertEquals(3, jobInstances.size());
for (JobInstance jobInstance : jobInstances) {
List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstance);
Assert.assertEquals(1, jobExecutions.size());
Assert.assertEquals(BatchStatus.FAILED, jobExecutions.get(0).getStatus());
}
mifosScheduler.runIndividualTask(jobName);
Thread.sleep(5000);
explorer = mifosScheduler.getBatchJobExplorer();
jobInstances = explorer.getJobInstances(jobName, 0, 10);
Assert.assertEquals(4, jobInstances.size());
JobInstance jobInstance = jobInstances.get(0);
JobExecution jobExecution = explorer.getJobExecutions(jobInstance).get(0);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
jobInstance = jobInstances.get(1);
jobExecution = explorer.getJobExecutions(jobInstance).get(0);
Assert.assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
Assert.assertEquals(ExitStatus.FAILED, jobExecution.getExitStatus());
jobInstance = jobInstances.get(2);
jobExecution = explorer.getJobExecutions(jobInstance).get(0);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
jobInstance = jobInstances.get(3);
jobExecution = explorer.getJobExecutions(jobInstance).get(0);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
Aggregations