Example usage for org.springframework.boot.autoconfigure.batch JobExecutionEvent JobExecutionEvent

List of usage examples for org.springframework.boot.autoconfigure.batch JobExecutionEvent JobExecutionEvent

Introduction

In this page you can find the example usage for org.springframework.boot.autoconfigure.batch JobExecutionEvent JobExecutionEvent.

Prototype

public JobExecutionEvent(JobExecution execution) 

Source Link

Document

Create a new JobExecutionEvent instance.

Usage

From source file:org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.java

protected void execute(Job job, JobParameters jobParameters)
        throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
        JobParametersInvalidException, JobParametersNotFoundException {
    JobParameters nextParameters = getNextJobParameters(job, jobParameters);
    if (nextParameters != null) {
        JobExecution execution = this.jobLauncher.run(job, nextParameters);
        if (this.publisher != null) {
            this.publisher.publishEvent(new JobExecutionEvent(execution));
        }//from  w w  w .j  av a 2s .co  m
    }
}

From source file:org.springframework.cloud.task.batch.handler.TaskJobLauncherCommandLineRunner.java

protected void execute(Job job, JobParameters jobParameters)
        throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
        JobParametersInvalidException, JobParametersNotFoundException {
    JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.jobExplorer)
            .getNextJobParameters(job).toJobParameters();
    JobExecution execution = this.jobLauncher.run(job, nextParameters);
    if (this.publisher != null) {
        this.publisher.publishEvent(new JobExecutionEvent(execution));
    }/*www .  ja  v  a2  s .  co  m*/
    if (execution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())) {
        String message = String.format(
                "Job %s failed during " + "execution for jobId %s with jobExecutionId of %s",
                execution.getJobInstance().getJobName(), execution.getJobId(), execution.getId());
        logger.error(message);
        throw new TaskException(message);
    }
}