Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Conversion corrections

Table of Contents
outlinh1. true
outlinh1. true
1printablefalse
2stylh1. none
3indent20px

The normal behaviour is that Job Scheduler handles exit codes <> 0 as an error. In dependence of the error handling, the order goes to error state or will be suspended/setbacked. You can change this behaviour by implementing a post processing. In this example job chain, the post processing is configured as a cdata for the reason of better readability. You can also provide a file with the post processing script to get an general error handling by including the file.

...

You can download the files from: sample_errorhandling.zip

Code Block

       <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job ]<job order="yes"
             stop_on_error="no"
             title="Just an Example Job"
             name="job_sample">
            <script language="shell">
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="shell">
                <    <![CDATA[
 Echo here is an example
                ]]>
            </script>
  
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]<run_time/>
        </job>
 
 

The first example

Code Block
        <job order="yes"
           <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job ]order="yes"
               stop_on_error="no"
             name="job_with_exit_code">
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="shell"<script language="shell">
                <![CDATA[
 rem this is a shell script ending with an exit code
 exit 0
                ]]>
            </script>
 
            <monitor name="exitCodeDispatcher"
      <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/monitor.xml monitor ]name="exitCodeDispatcher"               ordering="0">
                <script     orderinglanguage="0javascript">
                    <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="javascript">![CDATA[
 function spooler_task_after() {
   var exitCode = spooler_task.exit_code;
   var order          <![CDATA[
 function spooler_task_after()\{
   var exitCode = spooler_task.exit_code;
   var order = spooler_task= spooler_task.order;
    
   spooler_log.info ("Exit Code is: " + exitCode);
   result = true;
   
   switch (exitCode ) \{
   case 0: //example to proceed the job chain at another node
      spooler_log.info("proceeding with next step");
      break;
   case 1: //example to proceed the job chain at another node
      order.state="300"
      break;
   case 2: //example to end with an end state
      order.state="success:2"
      break;
    default: //Other exit codes are handled as an error
      //spooler_log.info("Exit Code of " + order.job_chain + "/" + order.id + " in node " + order.job_chain_node.state + " was " + exitCode);
      result = false;
      break;
     \}
  //If you want to avoid messages like
  //2011-08-04 10:13:14.531 [ERROR]  (Task sample/job_with_exit_code:1001447) SCHEDULER-280  Process terminated with exit code 1 (0x1)
  //spooler_task.exit_code = 0;
  return result;
 \}
 //This also could be done in a more generic way
 //See example in Step job_with_exit_code_generic
                    ]]>
                </script>
            </monitor>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]<run_time/>
        </job>
 

The second example

Code Block
        <job order="yes"
          <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job ]order="yes"
                stop_on_error="no"
             name="job_with_exit_code_generic">
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/params.xml params]/>
 
<params/>
 
            <script language="shell">
                <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="shell">
                <![CDATA[
 rem ![CDATA[
 rem another example
 exit 98
                ]]>
            </script>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/monitor.xml monitor ]<monitor name="exitCodeDispatcherGeneric"
                     ordering="0">
                <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]<script language="javascript">
                    <![CDATA[
 function spooler_task_after()\{
 //You define a node with exit.<exitCode> for each possible exitCode
 //If node is not defined, a default will be used
   var exitCode = spooler_task.exit_code;
   var order = spooler_task.order;
 
  if (exitCode != 0)\ {
    newState = "exit." + exitCode;
    try \{//Checking, wether node is defined in job chain configuration
      order.job_chain.node( newState )    
   \ } catch (e) \{
        order.state = "exit.default";
   \}
   order.state = "exit." + exitCode
   \}
   return true;
 \}
                    ]]>
                </script>
            </monitor>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]/>
        </job>
    </jobs>

Here is the job chain

Code Block

   <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain.xml job_chain] orders_recoverable="yes"
                   visible="yes"
   order.state = "exit." + exitCode
   }
   return true;
 }
                    title="Example for a job chain with handling exit codes"
]]>
                </script>
           name="job_chain_exit_code_dispatcher"> </monitor>
 
           <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] state="firstStep"
   <run_time/>
        </job>
    </jobs>

Here is the job chain

Code Block
   <job_chain orders_recoverable="yes"
          job="job_with_exit_code"
         visible="yes"
                   next_statetitle="secondStep"
Example for  a job chain with handling exit codes"
                   error_statename="error"/>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml jobjob_chain_exit_code_dispatcher">
            <job_chain_node] state="secondStepfirstStep"
                            job="job_with_exit_code_generic"
                            next_state="secondStep"
                            nexterror_state="200error"/>
 
            <job_chain_node state="secondStep"
              error_state="error"/>
 
              <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] state="200job="job_with_exit_code_generic"
                            errornext_state="error200"
                            job="job_sampleerror_state="error"/>
 
            <job_chain_node state="200"
                            nexterror_state="300error"/>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] state="300"
             job="job_sample"
               error_state="error"
             next_state="300"/>
 
              job<job_chain_node state="job_sample300"
                            nexterror_state="400error"/>
  
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] state="400              job="job_sample"
                            errornext_state="error400"/>
 
               <job_chain_node state="400"
            job="job_sample"
                error_state="error"
            next_state="success"/>
  
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] state="success"/>
 
  job="job_sample"
                         <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node]    next_state="success:2"/>
  
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job<job_chain_node state="success"/>
 
            <job_chain_node] state="errorsuccess:2"/>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job <job_chain_node state="error"/>
 
            <job_chain_node] state="exit.99"/>
 
            <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_<job_chain_node] state="exit.default"/>
        </job_chain>