[英]Spring batch execute last step even get an exception
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. 我想运行一个包含一组步骤的spring batch作业,最后我想向redis发送一个包含Job执行状态的通知。 Let's say if all the steps are executed, I should send "Pass". 假设所有步骤都执行了,我应该发送“ 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. 因此,我的最后一步将是通知Redis更新状态,无论状态是否正常或发生异常。
My question is: 我的问题是:
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. 但是我在这里像java -jar app.jar ----spring.batch.job.names=myjobnamehere
这样在命令行中调用作业,以便不使用java -jar app.jar ----spring.batch.job.names=myjobnamehere
对象。
You can use a JobExecutionListener
for that. 您可以为此使用JobExecutionListener
。 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. 在afterJob
方法,你必须在参考JobExecution
从中可以得到这份工作的状况,并根据需要发送通知。
You can find an example in the getting started guide (See JobCompletionNotificationListener
). 您可以在入门指南中找到一个示例(请参阅JobCompletionNotificationListener
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.