Changing the file name after the step completes
Hi,
we configured one step inside a job to read from a file and upload the items to a database. After the step is complete we want to change the file name.
If for some reason the name change fails the steps must not to be marked as completed so the change will be tried later.
The idea was to extend the class StepExecutionResourceProxy implementing the afterStep method and changing the file name there:
public ExitStatus afterStep(StepExecution stepExecution) {
final String oldFilename = getFilename();
ExitStatus exitStatus = stepExecution.getExitStatus();
if (!ExitStatus.FAILED.equals(exitStatus)) {
try {
boolean success =
getFile().renameTo(
new File(oldFilename.concat(".parsed")));
if (!success) {
if (logger.isErrorEnabled()) {
logger.error("It was not possible to rename the file:"
+ oldFilename + ". The reason is unknown.");
}
stepExecution.setStatus(BatchStatus.FAILED);
return ExitStatus.FAILED;
}
} catch (IOException e) {
if (logger.isErrorEnabled()) {
logger.error("It was not possible to rename the file:"
+ oldFilename + " for an input/output exception: "
+ e.getMessage());
}
stepExecution.setStatus(BatchStatus.FAILED);
return ExitStatus.FAILED;
}
}
// If the renaming goes well then we can return the exit status of the
// current context.
return stepExecution.getExitStatus();
}
and the listener is correctly added to the job. But what happen is that the status is set to COMPLETE then preventing the job to run again without an exception.
Have you any suggestion?
Is better to add another tasklet to the job for changing the file name? Someone has any example for that?
Thanks in advance,
Vicio.