0

I want to run a spring batch job which has set of steps and finally I want to send a notification to redis containing the status of the Job execution. Let's say if all the steps are executed, I should send "Pass". If there was any execution or any error, I want to pass "Fail". So my last step will be notification to redis updating the status regardless of it finished fine or got an exception.

My question is:

  1. Can I achieve this in Spring Batch?
  2. Can I use notification function as a last step or should I use any specific method for this?
  3. How can I get the status of jobs?

I know I can get the job status like :

 JobExecution execution = jobLauncher.run(job, params);
 System.out.println("Exit Status : " + execution.getStatus());

But I call the job in command-line like java -jar app.jar ----spring.batch.job.names=myjobnamehere so that I do not use a JobExecution object.

1 Answer 1

2

You can use a JobExecutionListener for that. In the afterJob method, you have a reference to the JobExecution from which you can get the status of the job and send the notification as required.

You can find an example in the getting started guide (See JobCompletionNotificationListener).

Sign up to request clarification or add additional context in comments.

1 Comment

perfect! Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.