Events

Question: How can I wait for an event in a job chain?

Introduction

In some cases it is necessary to wait for an event before proceeding with execution.

JobScheduler provides a solution to set off events and to handle these events on an active instance of the event service JobScheduler. However it is also possible to check for events in job chains and then conditionally proceed.
You find the complete documentation in scheduler_events.pdf - Documentation. In particular, how to define event handlers with JOE is described in chapter XML Event Handlers (However this should not be needed for the actual example here.)
To demonstrate how to create an event and wait for it in a job chain we will draw up a simple scenario:

  1. setting up a job to create the event. This is a stand alone job.
  2. setting up a job chain with a wait step in the middle. When the event arrives, the execution proceeds and the event will be deleted.
  3. setting up the jobs for deleting and checking the event.

Requirements

The JobScheduler must run using a database. The events are stored permanently in the table SCHEDULER_EVENTS.

Instructions

  • Unzip all files of test_event.zip into the ./config folder of your active instance of the event service JobScheduler installation. After unzipping you will have all the objects needed to run the example in the live/test_events subfolder.
  • Open the JS operations gui for the workload JobScheduler in your browser using http://scheduler_host:scheduler_port
  • Find the test_event/job chain_example_wait_for_event job chain and click on it.
  • Click in the job chain menu on "add order"
  • You see the order will run until the step 3 is reached. As the EVENT event does not exist, the order will wait for 10s and then check again.
  • Switch to the tab Jobs.
  • Find the test_event/job_event_add job chain and click on it.
  • In the Job menu press Start task immediately. This will create the EVENT event.
  • Switch to the tab Job Chains.
  • See the order proceeding with execution of the next step

How it works

The test_event/job_event_add job is a dummy shell script job with a post processing part. In the post processing the com.sos.jitl.eventing.EventMonitorTaskAfter JITL class is used to add an TEST.TEST_EVENT event.

The test_event/job chain_example_wait_for_event job chain has 2 dummy steps and the wait for event step. This step executes the test_event/job_event_check job to look for the desired event specified in the scheduler_event_spec parameter. As the events are stored in a xml object you have to specify a xpath expression here.

If the event is not raised, the order executes a setback. The wait time between two checks is configured in the delay_order_after_setback definition of the job (and the job chain node).

After adding the event, the order will proceed with the next step and the event will be removed.

The test_event/job chain_example_wait_for_event_db  job chain has 2 dummy steps and the wait for event step. This step executes the test_event/job_event_check_db job to look for the desired event. The difference to to first example is, that this job uses the events database. You can either specify parameters for event_id, event_class and exit_code to test for a specific event or you can specify a condition for the events you are waiting for.

example:

 class_a.event_1:99 and not (class_b.event2 or class_b.event3)
  
 if the event_1 in class class_a exists with exit_code=99 and event2 and event3 from class_b do not exist, this expression evaluates to true.

You also can specify how to handle the existing or not existing of events with the parameters handle_existing_as="error|success" or handle_not_existing_as="error|success"

example

 handle_existing_as=error will wait until the events do not exist

If the event is not raised, the order executes a setback. The wait time between two checks is configured in the delay_order_after_setback definition of the job (and the job chain node).

After adding the event, the order will proceed to the next step and the event will be removed.

Related Downloads