Search in sources :

Example 11 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class MifosScheduler method getJobsPreviousRunStatus.

public String getJobsPreviousRunStatus(String jobName) {
    JobExplorer explorer = getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
    if (jobInstances.size() == 0) {
        return "Never executed yet";
    }
    List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstances.get(0));
    if (jobExecutions.size() == 0) {
        return "Never executed yet";
    }
    String runStatus = jobExecutions.get(0).getStatus().toString();
    runStatus = runStatus.substring(0, 1) + runStatus.substring(1).toLowerCase();
    return runStatus;
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer)

Example 12 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class MifosBatchJob method checkAndLaunchJob.

/**
     * This method is a wrapper around launchJob method. It checks whether previous
     * runs of the job executed successfully and attempts to re-run them in case they did not.
     * @param job Job class
     * @param jobParameters Job parameters
     * @param lookUpDepth Counter used to track current recurrence depth
     * @return Batch computation status
     * @throws BatchJobException when something goes wrong
     */
public BatchStatus checkAndLaunchJob(Job job, JobParameters jobParameters, int lookUpDepth) throws BatchJobException {
    List<JobInstance> jobInstances = jobExplorer.getJobInstances(job.getName(), lookUpDepth, lookUpDepth + 1);
    if (jobInstances.size() == 0) {
        return launchJob(job, jobParameters);
    }
    JobInstance jobInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
    // latest execution
    JobExecution jobExecution = jobExecutions.get(0);
    if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
        return launchJob(job, jobParameters);
    }
    checkAndLaunchJob(job, jobExecution.getJobInstance().getJobParameters(), lookUpDepth + 1);
    return launchJob(job, jobParameters);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance)

Example 13 with JobExecution

use of org.springframework.batch.core.JobExecution in project camel by apache.

the class SpringBatchEndpointTest method shouldReturnJobExecution.

@Test
public void shouldReturnJobExecution() throws Exception {
    // Given
    JobExecution jobExecution = mock(JobExecution.class);
    when(jobLauncher.run(eq(job), any(JobParameters.class))).thenReturn(jobExecution);
    // When
    sendBody("direct:start", "Start the job, please.");
    // Then
    mockEndpoint.expectedBodiesReceived(jobExecution);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobParameters(org.springframework.batch.core.JobParameters) Test(org.junit.Test)

Example 14 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class LoanArrearsTaskIntegrationTest method testExecute.

@Test
public void testExecute() throws Exception {
    int statusChangeHistorySize = loanAccount.getAccountStatusChangeHistory().size();
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(1500);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertEquals(1, jobInstances.size());
    JobInstance lastInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = explorer.getJobExecutions(lastInstance);
    Assert.assertEquals(1, jobExecutions.size());
    JobExecution lastExecution = jobExecutions.get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, lastExecution.getStatus());
    StaticHibernateUtil.getSessionTL().refresh(loanAccount);
    loanAccount = legacyAccountDao.getAccount(loanAccount.getAccountId());
    Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, loanAccount.getState());
    Assert.assertEquals(statusChangeHistorySize + 1, loanAccount.getAccountStatusChangeHistory().size());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Test(org.junit.Test)

Example 15 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class ProductStatusHelperIntegrationTest method testExecuteTask.

@Test
public void testExecuteTask() throws Exception {
    createInactiveLoanOffering();
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/productStatusTestTask.xml");
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(1000);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertTrue(jobInstances.size() > 0);
    JobInstance lastInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = explorer.getJobExecutions(lastInstance);
    Assert.assertEquals(1, jobExecutions.size());
    JobExecution lastExecution = jobExecutions.get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, lastExecution.getStatus());
    product = (LoanOfferingBO) TestObjectFactory.getObject(LoanOfferingBO.class, product.getPrdOfferingId());
    Assert.assertEquals(PrdStatus.LOAN_ACTIVE, product.getStatus());
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) Test(org.junit.Test)

Aggregations

JobExecution (org.springframework.batch.core.JobExecution)19 JobInstance (org.springframework.batch.core.JobInstance)13 Test (org.junit.Test)11 JobExplorer (org.springframework.batch.core.explore.JobExplorer)11 Date (java.util.Date)4 JobParameters (org.springframework.batch.core.JobParameters)3 StepExecution (org.springframework.batch.core.StepExecution)3 JobLocator (org.springframework.batch.core.configuration.JobLocator)3 JobLauncher (org.springframework.batch.core.launch.JobLauncher)3 Ignore (org.junit.Ignore)2 BatchStatus (org.springframework.batch.core.BatchStatus)2 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 BatchJobException (org.mifos.framework.components.batchjobs.exceptions.BatchJobException)1 ProductStatus (org.mifos.framework.components.batchjobs.helpers.ProductStatus)1 CronTrigger (org.quartz.CronTrigger)1 JobDataMap (org.quartz.JobDataMap)1 JobDetail (org.quartz.JobDetail)1 JobExecutionContext (org.quartz.JobExecutionContext)1