Search in sources :

Example 1 with Job

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

the class MifosBatchJob method executeInternal.

@Override
public void executeInternal(JobExecutionContext context) throws JobExecutionException {
    try {
        String jobName = context.getJobDetail().getName();
        Job job = jobLocator.getJob(jobName);
        catchUpMissedLaunches(job, context);
        checkAndLaunchJob(job, getJobParametersFromContext(context), 0);
    } catch (Exception ex) {
        throw new JobExecutionException(ex);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) Job(org.springframework.batch.core.Job) StatefulJob(org.quartz.StatefulJob) ParseException(java.text.ParseException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) JobExecutionException(org.quartz.JobExecutionException) JobInstanceAlreadyCompleteException(org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException)

Example 2 with Job

use of org.springframework.batch.core.Job in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunner method executeRegisteredJobs.

private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecutionException {
    if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
        String[] jobsToRun = this.jobNames.split(",");
        for (String jobName : jobsToRun) {
            try {
                Job job = this.jobRegistry.getJob(jobName);
                if (this.jobs.contains(job)) {
                    continue;
                }
                execute(job, jobParameters);
            } catch (NoSuchJobException ex) {
                logger.debug("No job found in registry for job name: " + jobName);
                continue;
            }
        }
    }
}
Also used : NoSuchJobException(org.springframework.batch.core.launch.NoSuchJobException) Job(org.springframework.batch.core.Job)

Example 3 with Job

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

the class SpringBatchEndpointTest method shouldInjectJobRegistryByReferenceName.

@Test
public void shouldInjectJobRegistryByReferenceName() throws Exception {
    // Given
    Job mockJob = mock(Job.class);
    when(jobRegistry.getJob(eq("mockJob"))).thenReturn(mockJob);
    context().addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:jobRegistryRefTest").to("spring-batch:mockJob?jobRegistry=#jobRegistry");
        }
    });
    // When
    template.sendBody("direct:jobRegistryRefTest", "Start the job, please.");
    // Then
    SpringBatchEndpoint batchEndpoint = context().getEndpoint("spring-batch:mockJob?jobRegistry=#jobRegistry", SpringBatchEndpoint.class);
    JobRegistry batchEndpointJobRegistry = (JobRegistry) FieldUtils.readField(batchEndpoint, "jobRegistry", true);
    assertSame(jobRegistry, batchEndpointJobRegistry);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) JobRegistry(org.springframework.batch.core.configuration.JobRegistry) Job(org.springframework.batch.core.Job) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Example 4 with Job

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

the class SpringBatchEndpointTest method shouldConvertDateHeadersToJobParams.

@Test
public void shouldConvertDateHeadersToJobParams() throws Exception {
    // Given
    String headerKey = "headerKey";
    Date headerValue = new Date();
    // When
    template.sendBodyAndHeader("direct:start", "Start the job, please.", headerKey, headerValue);
    // Then
    ArgumentCaptor<JobParameters> jobParameters = ArgumentCaptor.forClass(JobParameters.class);
    verify(jobLauncher).run(any(Job.class), jobParameters.capture());
    Date parameter = jobParameters.getValue().getDate(headerKey);
    assertEquals(parameter, headerValue);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) Date(java.util.Date) Test(org.junit.Test)

Example 5 with Job

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

the class SpringBatchEndpointTest method setNullValueToJobParams.

@Test
public void setNullValueToJobParams() throws Exception {
    // Given
    String headerKey = "headerKey";
    Date headerValue = null;
    // When
    template.sendBodyAndHeader("direct:start", "Start the job, please.", headerKey, headerValue);
    // Then
    ArgumentCaptor<JobParameters> jobParameters = ArgumentCaptor.forClass(JobParameters.class);
    verify(jobLauncher).run(any(Job.class), jobParameters.capture());
    Date parameter = jobParameters.getValue().getDate(headerKey);
    assertEquals(parameter, headerValue);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Job (org.springframework.batch.core.Job)11 Test (org.junit.Test)6 JobParameters (org.springframework.batch.core.JobParameters)3 IOException (java.io.IOException)2 Date (java.util.Date)2 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 TaskSystemException (org.mifos.framework.components.batchjobs.exceptions.TaskSystemException)2 SchedulerException (org.quartz.SchedulerException)2 SimpleTrigger (org.quartz.SimpleTrigger)2 JobFactory (org.springframework.batch.core.configuration.JobFactory)2 SimpleJob (org.springframework.batch.core.job.SimpleJob)2 TaskletStep (org.springframework.batch.core.step.tasklet.TaskletStep)2 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)2 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 BatchJobException (org.mifos.framework.components.batchjobs.exceptions.BatchJobException)1 JobExecutionException (org.quartz.JobExecutionException)1