Table of Contents |
---|
| outlinh1. true |
---|
| outlinh1. true |
---|
1 | printablefalse |
---|
2 | stylh1. none |
---|
3 | indent20px |
---|
|
The normal behaviour is that Job Scheduler handles exit codes <> 0 as an error. In dependence of the error handling, the order go to error state or will be suspended/setbacked. You can change this behaviour by implementing a post processing. In this sample 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.
Here are two approaches. The first handles each exit code and the second is more generic. You switch between the samples by changing the exit code of the first step. When exit code is 0, the more generic sample will be executed. To see this in your environment, you can download the configuration files and put them into any folder in config/live.
You can download the files from: sample_errorhandling.zip
Code Block |
---|
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job ]order="yes"
stop_on_error="no"
title="Just a Sample Job"
name="job_sample">
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="shell">
<![CDATA[
|
Code Block |
---|
Echo here is a sample
|
Code Block |
---|
]]>
</script>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]/>
</job>
|
The first sample
Code Block |
---|
<[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">
<![CDATA[
rem this is a shell script ending with an exit code
exit 0
]]>
</script>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/monitor.xml monitor ]name="exitCodeDispatcher"
ordering="0">
<[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 = spooler_task.order;
spooler_log.info ("Exit Code is: " + exitCode);
result = true;
switch (exitCode ) \{
case 0: //sample to proceed the job chain at another node
spooler_log.info("proceeding with next step");
break;
case 1: //sample to proceed the job chain at another node
order.state="300"
break;
case 2: //sample 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 sample in Step job_with_exit_code_generic
]]>
</script>
</monitor>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]/>
</job>
|
The second sample
Info |
---|
|
Control of process flow has been improved by a generic feature Display feature availability |
---|
|
Jira |
---|
server | SOS JIRA |
---|
columns | key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
key | JS-1190 |
---|
|
|
- The normal behaviour is that JobScheduler handles exit codes <> 0 as an error.
- Depending on the error handling, the order moves to the error state, will be suspended or will enter a setback interval.
- You can modify this behaviour by implementing some post-processing:
- For the following example job chain the post-processing is configured as a CDATA element for better readability.
- You could also provide a file with a post-processing script to organise some general use of error handling by including the file to multiple job chains.
- There are two possible approaches:
- the first handles each exit code individually and
- the second is more generic.
- You switch between the examples by changing the exit code of the first step. If the exit code is 0, then the more generic example will be executed.
- To make this example work for your environment you can download the configuration files and add them to a folder in the ./config/live directory.
First Example
Job: job_with_exit_code
Code Block |
---|
language | xml |
---|
title | Job: job_with_exit_code |
---|
collapse | true |
---|
|
<job order="yes">
<script language="shell"><![CDATA[
rem this is a shell script ending with an exit code
exit 0
]]></script>
<monitor name="exitCodeDispatcher"
ordering="0">
<script language="javax.script:ECMAscript"><![CDATA[
function spooler_task_after() {
var exitCode = spooler_task.exit_code();
var order = 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.set_state( "300" );
break;
case 2: // example to end with an end state
order.set_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.set_exit_code( 0 );
return result;
}
// This could be done in a more generic way
// See example in step job_with_exit_code_generic
]]></script>
</monitor>
<run_time/>
</job> |
Second Example
Job: job_with_exit_code_generic
Code Block |
---|
language | xml |
---|
title | Job: job_with_exit_code_generic |
---|
collapse | true |
---|
|
<job order="yes |
Code Block |
---|
<[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]/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="shell">
<![CDATA[
rem another sample
exit 98
]]>
</script>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/monitor.xml monitor ]name="exitCodeDispatcherGeneric"
ordering="0">
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]language="javascript">
<params/>
<<script language="shell"><![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) \{ rem another example
exit 98
]]></script>
<monitor name="exitCodeDispatcherGeneric"
ordering="0">
order.state = "exit.default";
\}
order.state<script language= "exitjavax.script:ECMAscript" + 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"
><![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, whether node is defined in job chain configuration
order.job_chain().node( newState )
} catch (e) {
visible="yes"
title="Sample for a job chain with handling exit codes"
order.set_state( "exit.default" );
}
order.set_state( "exit." + exitCode );
}
return true;
}
]]></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> |
Job and Job Chain for both Examples
Job: job_sample
Code Block |
---|
language | xml |
---|
title | Job: job_sample |
---|
collapse | true |
---|
|
<job order="yes"
title="Just an Example Job">
<script job="job_with_exit_code"
language="shell"><![CDATA[
echo "here comes an example"
]]></script>
<run_time/>
</job>
|
Job Chain: job_chain_exit_code_dispatcher
Code Block |
---|
language | xml |
---|
title | Job Chain: job_chain_exit_code_dispatcher |
---|
collapse | true |
---|
|
<job_chain orders_recoverable="yes next_state="secondStep"
title="Example for a job chain with handling error_state="error"/>
exit codes">
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job <job_chain_node] state="secondStepfirstStep"
job="job_with_exit_code_generic"
next_state="200secondStep"
error_state="error"/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job<job_chain_node] state="200secondStep"
error_statejob="errorjob_with_exit_code_generic"
jobnext_state="job_sample200"
nexterror_state="300error"/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job <job_chain_node] state="300200"
error_state="error"
job="job_sample"
next_state="400300"/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job <job_chain_node] state="400300"
error_state="error"
job="job_sample"
next_state="400"/>
<job_chain_node state="400"
next_state="success"/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] error_state="successerror"/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] state="success:2"/>
job="job_sample"
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job_chain_node] next_state="errorsuccess"/>
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain_node.xml job<job_chain_node state="success"/>
<job_chain_node] state="exit.99success: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.default99"/>
<job_chain_node state="exit.default"/>
</job_chain>
|
Related Downloads
- Download the files from: sample_errorhandling.zip