Once the task of a job is finished, you can call various commands depending on its exit code (see http://www.sos-berlin.com/doc/en/scheduler.doc/xml/commands.xml).
These commands are especially "<start_job/>" or "<add_order/>".
Both commands are supported in JOE:
- go to command
- add a new command
- choose an exit code, 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 http://www.sos-berlin.com/doc/en/scheduler.doc/xml_commands.xml).
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. Exampleh1.
We have a standalone job which calls an 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.
<job title="handle_exit_codes_with_api"> <script language="shell"> <![CDATA[ ./config/live/test/test.sh ]]> </script> </job>
Without API
- set stop_on_erroh1. "no"
With API
- set stop_on_error"no"
- 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 ends 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 30 seconds"); spooler_job.state_text="Job restarts in 30 seconds"; spooler_job.delay_after_error(1) = "30"; 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; \} \}