The question is regarding to the auto-recovery strategy of the batch jobs. Saying the server was shut down due to unknown reasons when there were several jobs running (with status "STARTED" and null end time). How can we recover all these jobs when we start up the server again.
In my situation, I wrote my own job launcher to receive requests and save them into the DB queue. Then I run my own job scheduler to poll the requests from the DB and execute the jobs. In order to change these jobs' status from "STARTED" to "STARTING" in order to be picked up by my scheduler again, my current tries contain:
because spring batch cannot restart "STARTED" jobs, and even the job is restartable, spring batch will create a new job execution under the same job instance. Hence, if I can restart the job, the origin job id needs to be changed. But we I tried to use the job operator to stop the job with "STARTED" status, and then to restart it again, I failed. Why doesn't this work?
jobOperator.stop(jobId); jobOperator.restart(jobId);
I also failed to use the job repository to update the job execution status from "STARTED" to "STARTING".
jobExecution.setStatus(BatchStatus.STARTED); jobRepository.update(jobExecution);
Any thoughts of achieving this would be appreciated!