Could you show me a simple example of a job chain?
Question:
Does every job chain need an order to be triggered? Is there some simple example for the use of job chains and orders?
Answer:
Processing of a job chain is always triggered by an order. Therefore three elements have to be brought together: jobs, a job chain and an order.
Jobs, job chains and order are - like all JobScheduler objects - stored as flat XML files and can be configured as such. The jobs, job chains and orders presented in this article are presented at the XML level.
Note that we also have a graphical editor for JobScheduler objects - JOE - which allows form-based configuration of JobScheduler objects. The use of JOE to configure JobScheduler objects is described in our JobScheduler Tutorials series.
Jobs
Let's look at the job implementation. Any job could be used for a job chain, however the attribute
order="yes"
is required:<job name="command_1" title="sample_command" order="yes"> <script language="shell"> <![CDATA[ C:\Programme\Samples\Scripts\command_sample_1.cmd ]]> <script> </job> <job name="command_2" title="sample_command" order="yes"> <script language="shell"> <![CDATA[ C:\Programme\Samples\Scripts\command_sample_2.cmd ]]> <script> </job>
Job Chain
Next you need a job chain that assigns nodes and states to these jobs:
<job_chain name="command_sequence"> <job_chain_node state="first" job="command_1" next_state="second" error_state="error"/> <job_chain_node state="second" job="command_2" next_state="success" error_state="error"/> <job_chain_node state="success"/> <job_chain_node state="error"/> </job_chain>
This sample assigns the above job
command_1
the first node in the chain andcommand_2
the second node that will be executed if the first node were successfully completed. The chaining is organized by thenext_state
attribute that identifies the state of the next job node in a chain and respectively theerror_state
attribute that identifies the node that should be executed in case of error. Job nodes for final states could be empty as forsuccess
anderror
, moreover you could create job implementations for individual error handling.
Order
Last but not least you need an order that triggers the execution of the job chain:
<order job_chain="command_sequence" title="sample command sequence" replace="yes"> <params/> <!-- sample run time: repeat the execution of this order every day at the given time --> <run_time><period single_start="23:36"/></run_time> </order>
This order is used for three purposes:
- Trigger the execution of the job chain: You would not start a job chain by starting the first job node, but by starting the order. The built-in HTML interface of JobScheduler offers the respective operations for orders. Multiple orders could cause the parallel execution of jobs in a job chain. JobScheduler would then dynamically allocate tasks in parallel to these jobs.
Add parameters to the jobs within the job chain: Parameters from orders are added with precedence to the parameters of a job configuration
<job> <params> <param name="sample_name" value="sample_value"> </params> </job>
- Specify the run time for automated execution: Any periods for repeated execution could be set.
You could ask, why an order is required if parameters and run time periods could equally be added to jobs? The answer is the re-usability of jobs and job chains: you can use a range of orders with different parameter sets on the same job chain.