0

My batch task was triggered by end user, so I do not want to execute all batch jobs when application startup (with spring.batch.job.enabled=false).

But I hope there is a solution to deal with this below situation,

When application started spring-batch could continue the interrupted batch job caused by application restart or or exceptional interruption.

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
Dean Wong
  • 1
  • 2

1 Answers1

1

Resume of failed/interrupted job in Spring Batch is achieved by submitting same job with same job parameters.

Therefore you can do the following to resubmit failed jobs (assuming you are using DB to store job meta data)

  • By joining BATCH_JOB_INSTANCE and BATCH_JOB_EXECUTION table, find out all job instances with no completed job executions
  • find out the latest BATCH_JOB_EXECUTIONS for each of the above incomplete job instance, and lookup the corresponding job parameters from BATCH_JOB_EXECUTION_PARAMS
  • Resubmit the job using job name from BATCH_JOB_INSTANCE, and job parameters from BATCH_JOB_EXECUTION_PARAMS
Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • 1
    I believe there are easier way to retrieve similar information from JobOperator etc. You may take a look – Adrian Shum Jul 20 '17 at 07:20
  • you are right. JobOperator can be used to restart a stopped job. Question is does it restart the job from the point it stopped (basically resume) or it will treat the job as a newly submitted and process from beginning? – Kaps Nov 23 '17 at 09:50
  • why don't give it a try? :) if you are submitting with same job parameter, it will normally start from where it failed. – Adrian Shum Nov 23 '17 at 10:40
  • yeah, tried it. It actually resumes the stopped job. All `JobOperator` needs is the unique `executionId`, so the API is pretty straight forward and works great. – Kaps Nov 23 '17 at 10:56
  • @AdrianShum could you please check what am I doing wrong here in order to restart the interrupted batch jobs after application restart from the same execution and step: https://stackoverflow.com/questions/51568876/spring-batch-restart-uncompleted-jobs-from-the-same-execution-and-step – alexanoid Jul 30 '18 at 07:22
  • 1
    @alexanoid I don't think it is possible. It is simply against Spring Batch's design – Adrian Shum Jul 30 '18 at 07:34