Results 1 to 7 of 7

Thread: Control Flow on First Step

  1. #1
    Join Date
    Jul 2007
    Posts
    15

    Default Control Flow on First Step

    I have a job that can have 2 steps, and depending on arguments and how the job gets invoked, I may not want both steps to run. Sometimes I would like to perform step1 first, then step2, but other times I only want to perform step 2. Is there any way, aside from creating a pre-step that makes a decision on those arguments? I can interrogate the parms in the reader itself and just "return null", but I'd like to keep job flow logic out of the job.

  2. #2
    Join Date
    Jul 2007
    Posts
    15

    Default

    Right now I am simply exiting the first step if a certain parameter is not set. It seems like there should be a better way to do this.

  3. #3
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    I would use a decision to start the job. That decision would interrogate the parameters passed in and either send the user to step 1 or step 2 as required. This allows your steps to be decoupled of that flow (as they should be).
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  4. #4
    Join Date
    Jul 2007
    Posts
    15

    Default

    Thanks for you help.

  5. #5
    Join Date
    Jul 2007
    Posts
    15

    Default

    So, can you actually start the job with a decision? It looks like I'd have to create a fake step or something on which the decision would act.

  6. #6
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    The following is allowed:

    Code:
    	<job id="deciderFirstJob">
    		<decision decider="myDecider" id="decider1">
    			<next on="*" to="step1"/>
    			<next on="OTHER" to="step2"/>
    			<fail on="ERROR"/>
    		</decision>
    		<step id="step1" parent="formatFileStep"/>
    		<step id="step2" parent="formatFileStep"/>
    	</job>
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  7. #7
    Join Date
    Jul 2007
    Posts
    15

    Default

    It works, thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •