Announcement Announcement Module
Collapse
No announcement yet.
Skipping a step Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Skipping a step

    How to skip a step?

    Scenario:
    There are 3 steps in all.

    Job run-1
    Step-1 -> successful
    Step-2 -> some validation errors in run-1 (user ignores these errors and then job runs again as a run-2)
    Step-3 -> this step doesn't execute.

    Job run-2
    Step-3 -> step-1 and step-2 should be skipped and the job should start with step-3.

    Can i implement this with the Spring Batch? How?

    Thank you!

  • #2
    The framework should handle this when you implement a restartable job. The reference docs describe how to make a job and a step restartable.

    Comment


    • #3
      By default when you restart a job, it will start from where it left off. For example, if you have three steps, and the first one completes succesfully, but the second one fails half-way through, restarting the job will cause the first step to be skipped (since it finished successfully) and the second one to start from where it left off (half way through), before moving on to the final step.

      Comment


      • #4
        Originally posted by lucasward View Post
        By default when you restart a job, it will start from where it left off. For example, if you have three steps, and the first one completes succesfully, but the second one fails half-way through, restarting the job will cause the first step to be skipped (since it finished successfully) and the second one to start from where it left off (half way through), before moving on to the final step.
        In that case, i will need to terminate the job in the afterStep of step-2 (run-1). (Beacuse error in the stpe-2 is just some business error, which should not stop step-2.)

        I tried using setTerminateOnly in my listener but it didn't work (Job went on to step-3). Could i be missing something?

        Comment


        • #5
          I believe that's a bug in 1.0:

          http://jira.springframework.org/browse/BATCH-532

          There's a workaround in the comments.

          Comment


          • #6
            Originally posted by lucasward View Post
            I believe that's a bug in 1.0:

            http://jira.springframework.org/browse/BATCH-532

            There's a workaround in the comments.
            Thanks Lucas!

            Last comment, in BATCH-532, says "listener.afterStep() call moved from catch block to the end of the try block - exception thrown in listener therefore causes the step to fail. "

            I tried throwing the RuntimeException from afterStep of step-2 (so as to terminate the job and not to proceed with step-3). However, this exception gets handled in ItemOrientedStep and continues with the step-3. What do i do now?

            Comment


            • #7
              Keep in mind that the change in the comments was in trunk (1.0.1) and so it will work a bit differently in 1.0. The workaround listed in the comments is this:

              "The workaround is to change the BatchStatus manually in the StepExecutionListener."

              So, in afterStep, called something like StepExecution.setStatus(BatchStatus.FAILED)

              Comment

              Working...
              X