Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: 'Job Chain, Jobs and Orders' rewritten

...

The Job Chain, Jobs and Orders

The

...

Job Chain

The Job Chain ...The Parent Order, in this example, with ID main_order has the following configuration. 

Code Block
languagexml
titleThe y_join Job Chain
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="ISO-8859-1"?>
<job_chain  title="Y Join">
    <job_chain_node  state="100" job="generate_orders" next_state="wait" error_state="error"/>
    <job_chain_node  state="150" job="job_a" next_state="join" error_state="error" delay="10"/>
    <job_chain_node  state="wait" job="wait" next_state="join" error_state="error"/>
    <job_chain_node  state="join" job="join" next_state="200" error_state="error"/>
    <job_chain_node  state="200" job="job_b" next_state="success" error_state="error"/>
    <job_chain_node  state="success"/>
    <job_chain_node  state="error"/>
</job_chain>

The Jobs

The Join Job

The configuration of the Join Job is set using the Wizard in following code block generate_orders Job contains the following script:

Code Block
languagexml
titleThe generatey_orders join Job Chain
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="ISO-8859-1"?>

<job  order="yes" stop_on_error="no">
    <script  language="java:javascript" idle_timeout="60" title="Join Job">
    <settings >
        <<log_level ><![CDATA[
function spooler_process(){

debug9]]></log_level>
    // merge parameters from task and order
<history_on_process ><![CDATA[0]]></history_on_process>
      var params = spooler_task.params;<history_with_log ><![CDATA[gzip]]></history_with_log>
    params.merge( spooler_task.order.params );
 </settings>
    <params >
    // set variable
  <param  var generate_orders = params.value( 'generate_orders' );name="show_join_order_list" value="true"/>
    </params>
    var<script jobChain language="java" java_class_path="" java_class="com.sos.jitl.join.JobSchedulerJoinOrdersJSAdapterClass"/>
    <run_time />
</job>

 

The generate_orders Job

The configuration of the generate_orders Job is shown in the next code block along with the script responsible for the generation of the Child Orders.

Note that this Job is only used to create the current demonstration of the Join Job and in not required for the Join Job itself.

Code Block
languagexml
titleThe generate_orders Job
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="ISO-8859-1"?>

<job  order="yes" stop_on_error="no">
    <script  language="java:javascript"> spooler.job_chain('/test/join/y_join/y_join');

    // log parameter
    spooler_log.info( 'generate_orders = ' + generate_orders);
 
    // generate orders
    for (i=0;i<generate_orders;i++){
       var order = spooler.create_order();
       order.id = spooler_task.order.id + "_" + i;
       order.params.merge(spooler_task.order.params); <![CDATA[
function spooler_process(){

    // merge parameters order.end_state="join";from task and order
    var params = order.state="150"spooler_task.params;
       jobChain.add_order(orderparams.merge( spooler_task.order.params );
 
   }

 // set variable
 return true;
}
  var generate_orders = params.value(   ]]>'generate_orders' );
    </script>

var jobChain =  <run_time />
</job>

The Order starts the first Job (generate) in the y_join Job Chain:

  • this Job contains a script that generates the Child Orders (see line XX of the listing) for the branch of the Job Chain from the job_nix Job to the join Job.

 

As the end_state for the generated Orders is the join Job state, these orders will be registered by the join job and counted towards to the value set by the ... parameter (12)

The Orders

The Main Order

The main Order in this example has 3 parameters:

  • required_orders
    • This parameter (Default 12.)
  • wait_time
    • this is the time in seconds that the Wait Job will wait before the main Order moves to the Join Job. (Default 35 secs.)
    • This parameter is not required by the Join Job.
  • generate_orders
    • this is the number of Orders that are to be generated by the generate_orders Job. (Default 10.) 
    • This parameter is not required by the Join Job.

The Child Orders

The main_order_add-order Order

This Order is configured with:

  • state = 150 (The state in the Job Chain where the Order starts processing. Here this corresponds to job_a) and
  • end_state = join (The state corresponding to the Join Job) This means that this Order will be registered by the Join Job as counting towards the required orders.

 

.....

Code Block
languagexml
titleThe main_order Order
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="ISO-8859-1"?>
<order >
    <params >
        <param  name="required_orders" value="12"/>
        <param  name="wait_time" value="35"/>
        <param  name="generate_orders" value="10"/>
    </params>
    <run_time />
</order>

...

spooler.job_chain('/test/join/y_join/y_join');

    // log parameter
    spooler_log.info( 'generate_orders = ' + generate_orders);
 
    // generate orders
    for (i=0;i<generate_orders;i++){
       var order = spooler.create_order();
       order.id = spooler_task.order.id + "_" + i;
       order.params.merge(spooler_task.order.params);
       order.end_state="join";
       if((i%2)==1) {
          order.state="150";
       } else {
          order.state="160";
       }
       jobChain.add_order(order);
    }

    return true;
}
        ]]>
    </script>

    <run_time />
</job>

The Order starts the first Job (generate) in the y_join Job Chain:

  • This Job contains a script that generates the Child Orders (see lines 20 - 31 of the listing). The Orders are alternated between the two branches of the Job Chain (even numbered Orders start at the Job corresponding with the Order state 150 and odd numbered Orders at the Job corresponding with the Order state 160). All Child Orders terminate at the Join Job.

The Orders

The Parent Order

The Parent Order, in this example, with ID main_order has the following 3 parameters:

  • required_orders
    • This parameter (Default 12.)
    • This parameter is required for the Join Job.
  • wait_time
    • this is the time in seconds that the Wait Job will wait before the main Order moves to the Join Job. (Default 35 secs.)
    • The wait_time parameter is used in the Wait Job as part of this example and is not necessary for the functioning of the Join Job.
  • generate_orders
    • this is the number of Orders that are to be generated by the generate_orders Job. (Default 10.) 
    • The generate_orders parameter is used in the Generate Job as part of this example to specify the number of Child Orders that should be generated. This parameter is not necessary for the functioning of the Join Job as the Jobs counted by the Join Job could come from any number of sources..
Code Block
languagexml
titleThe main_order Order
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="ISO-8859-1"?>
<order >
    <params >
        <param  name="required_orders" value="12"/>
        <param  name="wait_time" value="35"/>
        <param  name="generate_orders" value="10"/>
    </params>
    <run_time />
</order>

The Child Orders

The generated Child Orders

Have the ID of the Parent Order (main_order) + "_" + * where * is a string - in the current example simple numbers are used a string.

Have either:

  • <order state="150" end_state="join"> or
  • <order state="160" end_state="join">

depending on which branch of the Job Chain they should be executed on.

The main_order_add-order Order

Has the ID of the Parent Order (main_order) + "_" + * where * is a string - in the current example "add-order" is used.

This Order is configured with:

  • state = 150 (The state in the Job Chain where the Order starts processing. Here this corresponds to job_a) and
  • end_state = join (The state corresponding to the Join Job) This means that this Order will be registered by the Join Job as counting towards the required orders.
Code Block
languagexml
titleThe main_order_add-order Order
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="ISO-8859-1"?>
<order  state="150" end_state="join">
    <run_time />
</order>

...