Commands on Exit Codes
Once the task of a job has terminated you can call various commands depending on its exit code (see commands element).
These commands are particularly "start_job" and "add_order".
Both commands are supported in JOE:
- Go to command
- Add a new command
- Set the exit code for which the command will be called
- Use the add job or add order buttons to select the command
There are other rare use cases for commands (see list of XML commands).
Other commands may also be indicated in JOE, however, you have to use the "edit XML" function in the context menu of a job to add such commands. A panel will be displayed where you can insert the command.
Example for a Standalone Job
We assume 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 the job stops.
- If the exit code is 5 then the job restarts in 1 hour.
- All other exit codes can be ignored and will treated in the same way as the exit code 0.
<job> <script language="shell"><![CDATA[ ./config/live/test/test.sh ]]></script> <run_time]> <period single_start="12:00"/> <period begin="00:00:01" end="24:00"/> </run_time> </job>
Without API
- Set the job attribute stop_on_error to the value
no
- Add command for exit code 1:
<modify_job job="/test/call_test" cmd="stop"/>
- Add command for exit code 5:
<start_job job="/test/call_test" at="now + 01:00"/>
- Complete the shell script in which you store the exit code and change it in accordance with the requirement
The above example is added to a job definition like this:
With API
- Set the job attribute stop_on_error to the value
no
(a checkbox right above in the job main formular in JOE) - Add Pre-/Post-processing and insert the following Javascript lines.
- You will find the API documentation at http://www.sos-berlin.com/doc/en/scheduler.doc/api/api.xml.
- Consider the use of scripting languages in the below examples. The use of
<script language="java:javascript">
allows most compatible use of Javascript across 32 bit and 64 bit environments with Java versions up to 1.7 (scripting engine: Rhino) and later (scripting engine: Nashorn). For details see What are the differences between the SpiderMonkey, Rhino and Nashorn scripting engines?
The above example is added to a job definition like this:
Example for an Order Job
We assume an order 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 the order should stop.
- If the exit code is 5 then the order should restart in 1 hour.
- All other exit codes can be ignored and will be treated as exit code 0.
<job order="yes" stop_on_error="no"> <script] language="shell"><![CDATA[ ./config/live/test/test.sh ]]></script> </job>
Usage with the API
- Set the job attribute stop_on_error to the value
no
(a checkbox right above in the job main form in JOE) - Add Pre-/Post-processing and insert the below Javascript line
- You will find the API documentation at http://www.sos-berlin.com/doc/en/scheduler.doc/api/api.xml.
- Consider the use of scripting languages in the below examples. The use of
<script language="java:javascript">
allows most compatible use of Javascript across 32 bit and 64 bit environments with Java versions up to 1.7 (scripting engine: Rhino) and later (scripting engine: Nashorn). For details see What are the differences between the SpiderMonkey, Rhino and Nashorn scripting engines?
The above example is added to a job definition like this: