You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 22 Next »

Once the task of a job is finished, you can call various commands depending on its exit code (see commands element).

These commands are especially "start_job" or "add_order".

Both commands are supported in JOE:

  • go to command
  • add a new command
  • set the exit code for which the command will called, where errorh1. (exit code <> 0) and _success(exit code h2. 0)
  • use the add job or add order buttons to select the command

There are other more rare use commands (see list of XML commands).

The other commands may also be indicated on JOE, but you must use the "edit XML" function in the context menu of a job.

You get an textarea where you can insert the command. Example for a Standalone Jobh1.
We have a standalone job (./config/live/test/call_test.job.xml) which calls a shell script. This shell script returns various exit codes.

If the exit code is 1 then you want that the job stops.

If the exit code is 5 then you want that the job restarts in 1 hour.

All other exit codes can be ignored and will set equals 0.

 <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job]>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script] language="shell">
         <![CDATA[
 ./config/live/test/test.sh
         ]]>
     </script>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]>
        <period single_start="12:00"/>
        <period begin="00:00:01" end="24:00"/>
     </run_time>
 </job>

Without API

  1. set stop_on_erroh1. "no"
  2. add command for exit code 1: <modify_job job="/test/call_test" cmd="stop"/>
  3. add command for exit code 5: <start_job job="/test/call_test" at="now + 01:00"/>
  4. complement the shell script in which you store the exit code and change it in accordance with the requirement
  ./config/live/test/test.sh
  RC=$?
  case "$RC" in
  	"0")	echo "Script has ended with exit code $RC"
  		;;
  	"1")	echo "Script has ended with exit code $RC" >&2
  		echo "Job will stopped" >&2
  		;;
  	"5")	echo "Script has ended with exit code $RC" >&2
  		echo "Job restarts in 1 hour"
  		;;
  	*) 	echo "Script has ended with exit code $RC" >&2
  		echo "Exit code changed to 0"
  		RC=0
  		;;
  esac
  exit $RC

The above example has the final form:

 <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job] stop_on_error="no">
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script] language="shell">
         <![CDATA[
 ./config/live/test/test.sh
 RC=$?
 case "$RC" in
 	"0")	echo "Script has ended with exit code $RC"
 		;;
 	"1")	echo "Script has ended with exit code $RC" >&2
 		echo "Job will stopped" >&2
 		;;
 	"5")	echo "Script has ended with exit code $RC" >&2
 		echo "Job restarts in 1 hour"
 		;;
 	*) 	echo "Script has ended with exit code $RC" >&2
 		echo "Exit code changed to 0"
 		RC=0
 		;;
 esac
 exit $RC
         ]]>
     </script>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]>
        <period single_start="12:00"/>
        <period begin="00:00:01" end="24:00"/>
     </run_time>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/commands.xml commands] on_exit_code="1">
         <modify_job job="/test/call_test" cmd="stop"/>
     </commands>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/commands.xml commands] on_exit_code="5">
         <start_job job="/test/call_test" at="now + 01:00">
             <params><copy_params from="task"/></params>
         </start_job>
     </commands>
 </job> 

With API

  1. set stop_on_error"no" (a checkbox right above in the job main formular in JOE)
  2. add Pre-/Postprocessing and insert the following javascript lines
    You find the API documentation at http://www.sos-berlin.com/doc/en/scheduler.doc/api/api.xml.
 function spooler_task_after()\{
 	spooler_job.clear_delay_after_error();
 	var rc = spooler_task.exit_code;
 	switch(rc) \{
 		case  0 : 
 			spooler_log.info("Script has ended with exit code " + rc);
 			break;
 		case  1 : 
 			spooler_log.error("Script has ended with exit code " + rc);
 			spooler_log.error("Job will stopped");
 			spooler_job.delay_after_error(1) = "stop";
 			break;
 		case  5 : 
 			spooler_log.error("Script has ended with exit code " + rc);
 			spooler_log.info("Job restarts in 1 hour");
 			spooler_job.state_text="Job restarts in 1 hour";
 			spooler_job.delay_after_error(1) = "01:00:00";
 			break;
 		default : 
 			spooler_log.warn("Script has ended with exit code " + rc);
 			spooler_log.info("Exit code changed to 0");
 			spooler_task.exit_code = 0;
 			break;
 	\}
 \}

The above example has the final form:

 <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job] stop_on_error="no">
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script] language="shell">
         <![CDATA[
 ./config/live/test/test.sh
         ]]>
     </script>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/monitor.xml monitor] name="exit_code_handler" ordering="0">
         <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script] language="javascript">
             <![CDATA[
 function spooler_task_after()\{
 	spooler_job.clear_delay_after_error();
 	var rc = spooler_task.exit_code;
 	switch(rc) \{
 		case  0 : 
 			spooler_log.info("Script has ended with exit code " + rc);
 			break;
 		case  1 : 
 			spooler_log.error("Script has ended with exit code " + rc);
 			spooler_log.info("Job will stopped");
 			spooler_job.state_text="Job will stopped";
 			spooler_job.delay_after_error(1) = "stop";
 			break;
 		case  5 : 
 			spooler_log.error("Script has ended with exit code " + rc);
 			spooler_log.info("Job restarts in 1 hour");
 			spooler_job.state_text="Job restarts in 1 hour";
 			spooler_job.delay_after_error(1) = "01:00:00";
 			break;
 		default : 
 			spooler_log.warn("Job has ended with exit code " + rc);
 			spooler_log.info("Exit code changed to 0");
 			spooler_task.exit_code = 0;
 			break;
 	\}
 \}
             ]]>
         </script>
     </monitor>
     <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]>
        <period single_start="12:00"/>
        <period begin="00:00:01" end="24:00"/>
     </run_time>
 </job>
  • No labels