Spring Batch resume after server's failure

后端 未结 4 455
既然无缘
既然无缘 2021-02-04 06:53

I am using spring batch to parse files and I have the following scenario:

I am running a job. This job has to parse a giving file. For unexpected reason (let say for pow

4条回答
  •  情书的邮戳
    2021-02-04 07:24

    you can also write like below :

        @RequestMapping(value = "/updateStatusAndRestart/{jobId}/{stepId}", method = GET)
        public ResponseEntity updateBatchStatus(@PathVariable("jobId") Long jobExecutionId ,@PathVariable("stepId")Long stepExecutionId )throws Exception {
    
           StepExecution stepExecution =  jobExplorer.getStepExecution(jobExecutionId,stepExecutionId);
                stepExecution.setEndTime(new Date(System.currentTimeMillis()));
                stepExecution.setStatus(BatchStatus.FAILED);
                stepExecution.setExitStatus(ExitStatus.FAILED);
            jobRepository.update(stepExecution);
    
           JobExecution jobExecution =  stepExecution.getJobExecution();
                jobExecution.setEndTime(new Date(System.currentTimeMillis()));
                jobExecution.setStatus(BatchStatus.FAILED);
                jobExecution.setExitStatus(ExitStatus.FAILED);
            jobRepository.update(jobExecution);
            jobOperator.restart(execution.getId());
            
            return new ResponseEntity("

    Batch Status Updated !!

    ", HttpStatus.OK); }

    Here i have used restApi endpoint to pass the jobExecutionId and stepExecutionId and setting the status of both job_execution and step_execution to FAIL. then restart using batch operator.

提交回复
热议问题