Job Execution Listener is failed to store value in Job Execution Context Table

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Job Execution Listener is failed to store value in Job Execution Context Table



I have implemented the function to store number of processed with failure and success into job execution context in afterJob() method of JobExecutionListener implemented:


public void afterJob(JobExecution jobExecution) {
final long jobExecutionId = jobExecution.getId();
final BatchStatus jobStatus = jobExecution.getStatus();
final ExecutionContext jobExecutionContext = jobExecution.getExecutionContext();

String exitCodeAndMessage = null;
Map<String, Integer> recordsProcessed = null;

switch (jobStatus) {
case COMPLETED:
//exitCodeAndMessage = getExitCodeAndMessageFromEveryStep(jobExecution);
recordsProcessed = getExitCodeAndMessageFromEveryStep(jobExecution);
if (exitCodeAndMessage == null) {
exitCodeAndMessage = "COMPLETED";
}
jobExecutionContext.putString("AfterJob", "Success");
jobExecutionContext.put("recordsProcessed", recordsProcessed);
break;



After running the job, there is no value stored inside the table. Why?





None of the code you wrote writes information to the DB, and the JobExecution has already completed so Spring is not going to persist any changes you make to the context at this point.
– Joe Chiavaroli
yesterday





How do I need to add code in order to write information to the DB?
– user3865583
yesterday




1 Answer
1



The job execution context is not saved after the job is finished but is saved in between every step execution. So you can use a StepExecutionListener and add these metrics in the afterStep method. More details on this here: https://docs.spring.io/spring-batch/4.0.x/reference/html/domain.html#executioncontext


StepExecutionListener


afterStep






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

L fODCtH1A DS
evCeZl n68cy5QYFJlqhei656nxKQk,mUkzqbl,DfpF5owI URPb62D05FuLeRdyx,GfLcK

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template