Topic
4 replies Latest Post - ‏2012-12-05T08:15:50Z by planetjones
planetjones
planetjones
7 Posts
ACCEPTED ANSWER

Pinned topic Step Scheduling - skip rest of steps dependent on job return code

‏2012-11-30T13:19:00Z |
Hi there,

I have an XJCL with a lot of steps in it e.g.

STEP1
STEP2
STEP3
STEP4
STEP5

What I want to do is say that if any step returns a job code of > 4 skip all remaining steps and complete the Batch Job.

How do I do this ?

What I thought was pasting something like this into STEP2, STEP3, STEP4 and STEP5:

<step-scheduling>
<returncode-expression step="*" operator="gt" value="4" />
</step-scheduling>

But validation fails because the step attribute (which is mandatory) needs to match a valid step name i.e. no wildcards. I don't know which step will return the code to say skip all remaining steps so I can't code step names - unless it supports multiple returncode-expression elements or a comma separated list of step names. This sounds messy.

Alternatively maybe the processJobStep method could return a code which completes the whole job - but I can only find codes which put the job into a Restartable state, which is not what I want.

Surely I'm missing something ?

Thanks a lot.
Updated on 2012-12-05T08:15:50Z at 2012-12-05T08:15:50Z by planetjones
  • sspavan
    sspavan
    60 Posts
    ACCEPTED ANSWER

    Re: Step Scheduling - skip rest of steps dependent on job return code

    ‏2012-12-01T23:40:41Z  in response to planetjones
    Hi,

    I think you can achieve by implementing Custom ResultsAlgorithm instead of JobSum ResultsAlgorithm. The ResultsAlgorithm will be called at end of each batch step and you should be able to control the job flow from it.

    Thanks,
    Pavan
    • planetjones
      planetjones
      7 Posts
      ACCEPTED ANSWER

      Re: Step Scheduling - skip rest of steps dependent on job return code

      ‏2012-12-03T12:10:47Z  in response to sspavan
      Hi Pavan,

      Thanks for your reply. I see the interface, where I can implement a custom results algorithm:

      
      fireResultsAlgorithms(java.lang.String jobid,java.lang.String stepname,
      
      int steprc,
      
      int jobrc)
      


      What I want to do is something like:

      
      
      
      if steprc == 8 set jobrec == 0 complete job (don
      't execute any further steps)
      


      Do you know how this can be accomplished ? I do not see any API for completing the job from within the results algorithm.

      Thanks - Jonathan.
      • sspavan
        sspavan
        60 Posts
        ACCEPTED ANSWER

        Re: Step Scheduling - skip rest of steps dependent on job return code

        ‏2012-12-04T16:43:41Z  in response to planetjones
        I tried and couldn't set the job completion status. I tried below to fail the job but job ended normally

        if (arg1.equals("step1")) {
        System.out.println(" in checkkkkkkkkkkkkkkkkkk");
        return 16;
        }
        else
        return 0;

        Also tried to return step failure but job ended normally

        if (arg1.equals("step1")) {
        System.out.println(" in checkkkkkkkkkkkkkkkkkk " + BatchConstants.STEP_COMPLETE_EXECUTION_FAILED);
        return BatchConstants.STEP_COMPLETE_EXECUTION_FAILED;
        }
        else
        return 0;
        }

        So couldn't set the job completion status from the results algorithm. Don't know if we are missing something.
        Thanks,
        Pavan
        • planetjones
          planetjones
          7 Posts
          ACCEPTED ANSWER

          Re: Step Scheduling - skip rest of steps dependent on job return code

          ‏2012-12-05T08:15:50Z  in response to sspavan
          Hi Pavan,

          Thanks for trying. Your experiments have concluded the same way as mine !

          The solution I have gone for is not nice. On any step it has an AND condition which includes all previous steps e.g.

          
          <job-step name=
          "Step8">   <step-scheduling condition=
          "AND"> <returncode-expression step=
          "Step1" operator=
          "lt" value=
          "8" /> <returncode-expression step=
          "Step2" operator=
          "lt" value=
          "8" /> <returncode-expression step=
          "Step3" operator=
          "lt" value=
          "8" /> <returncode-expression step=
          "Step4" operator=
          "lt" value=
          "8" /> <returncode-expression step=
          "Step5" operator=
          "lt" value=
          "8" /> <returncode-expression step=
          "Step6" operator=
          "lt" value=
          "8" /> <returncode-expression step=
          "Step7" operator=
          "lt" value=
          "8" /> </step-scheduling>
          


          I don't like this, as it leads to an explosion of condfiguration. If an earlier step is introduced then I have to update all subsequent steps. Surely XJCL has a solution for this !?

          I am wondering if I am best off writing something persistent e.g. DB record or file, if a step decides it should cancel the whole job - then just having an if condition as the starting statement in each processJobStep i.e.

          
          
          
          if flag set 
          
          return step complete
          


          I don't see why a step can't say "i don't need to execute the rest of the steps, complete the job now" though.

          thanks again.