Mark steps and job as failed
Hi,
I have a job consisting of one step. That step is going through a list of input items and while processing it, it might generate a warning on an item. These warnings are logged. Now I want the step to have ExitStatus "COMPLETED_WITH_WARNINGS" when a warning has been given on one of it's items. After a warning, an operator should be able to rerun that job, so I want to mark the step (and the complete job) as having FAILED. How can I do this?
In my attempt so far, I created a StepExecutionListener that checks the ExecutionContext for warnings. Since I want to return an ExitStatus I cannot throw an Exception to make the job fail. Therefore, I tried to set the step status with stepExecution.upgradeStatus(BatchStatus.FAILED) before returning a ExitStatus, but that seems not to be the right approach; when a step fails this way, I get an error message "Encountered an error saving batch meta data.This job is now in an unknown state and should not be restarted." (without an exception being logged) and the status of the step execution is STARTED. From an earlier post I also understood it not good to interfere with the status.
So what is the right way to do this?
Regards,
Pieter