org.springframework.boot.autoconfigure.batch.JobExecutionEvent Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.batch.JobExecutionEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingleJobCommandLineRunner.java    From spring-boot-doma2-sample with Apache License 2.0 6 votes vote down vote up
protected BatchStatus execute(Job job, JobParameters jobParameters)
        throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
        JobParametersInvalidException, JobParametersNotFoundException {

    BatchStatus status = BatchStatus.UNKNOWN;
    val nextParameters = getNextJobParameters(job, jobParameters);

    if (nextParameters != null) {
        val execution = jobLauncher.run(job, nextParameters);

        if (publisher != null) {
            publisher.publishEvent(new JobExecutionEvent(execution));
        }

        status = execution.getStatus();
    }

    return status;
}
 
Example #2
Source File: JobExecutionListener.java    From messaging with Apache License 2.0 5 votes vote down vote up
@EventListener(JobExecutionEvent.class)
public void job(JobExecutionEvent executionEvent) {
 log.info("jobExecutionEvent: "
  + executionEvent.getJobExecution().toString());
 jdbcTemplate.query("select * from CONTACT", (RowCallbackHandler) rs -> log
  .info(String.format("id=%s, full_name=%s, email=%s, valid_email=%s",
   rs.getLong("id"), rs.getString("full_name"), rs.getString("email"),
   rs.getBoolean("valid_email"))));
}
 
Example #3
Source File: ContactBatchJobConfiguration.java    From building-microservices with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(JobExecutionEvent event) {
	System.out.println("finished " + event.getJobExecution().toString());
	this.jdbcTemplate
			.query("SELECT first_name, last_name, email FROM contact",
					(rs, i) -> new Contact(rs.getString("first_name"),
							rs.getString("last_name"), rs.getString("email")))
			.forEach(System.out::println);
}
 
Example #4
Source File: TaskJobLauncherCommandLineRunner.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
protected void execute(Job job, JobParameters jobParameters)
		throws JobExecutionAlreadyRunningException, JobRestartException,
		JobInstanceAlreadyCompleteException, JobParametersInvalidException {
	String jobName = job.getName();
	JobParameters parameters = jobParameters;
	boolean jobInstanceExists = this.taskJobRepository.isJobInstanceExists(jobName,
			parameters);
	if (jobInstanceExists) {
		JobExecution lastJobExecution = this.taskJobRepository
				.getLastJobExecution(jobName, jobParameters);
		if (lastJobExecution != null && isStoppedOrFailed(lastJobExecution)
				&& job.isRestartable()) {
			// Retry a failed or stopped execution with previous parameters
			JobParameters previousParameters = lastJobExecution.getJobParameters();
			/*
			 * remove Non-identifying parameters from the previous execution's
			 * parameters since there is no way to remove them programmatically. If
			 * they are required (or need to be modified) on a restart, they need to
			 * be (re)specified.
			 */
			JobParameters previousIdentifyingParameters = removeNonIdentifying(
					previousParameters);
			// merge additional parameters with previous ones (overriding those with
			// the same key)
			parameters = merge(previousIdentifyingParameters, jobParameters);
		}
	}
	else {
		JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
		if (incrementer != null) {
			JobParameters nextParameters = new JobParametersBuilder(jobParameters,
					this.taskJobExplorer).getNextJobParameters(job).toJobParameters();
			parameters = merge(nextParameters, jobParameters);
		}
	}
	JobExecution execution = this.taskJobLauncher.run(job, parameters);
	if (this.taskApplicationEventPublisher != null) {
		this.taskApplicationEventPublisher
				.publishEvent(new JobExecutionEvent(execution));
	}
	this.jobExecutionList.add(execution);
	if (execution.getStatus().equals(BatchStatus.FAILED)) {
		throwJobFailedException(Collections.singletonList(execution));
	}
}