Dependency Rules

Dependency rules are a very powerful feature. This feature allows one Job to affect the scheduling rules of other Jobs. The best way to describe it, is to use an example. Say you have Jobs C and B that run every day at 8:00am, but they must not run until Job A runs before them. And Job A normally runs at 2:00am. If for some reason Job A fails to run at its expected time, Jobs C and B must not run untill Job A completes. This is just one example of how to use Dependency Rules.

A Job can be associated to up to three Dependency Rules. If a Job's schedule is impacted by a Dependency Rule (that prevents it from running on a scheduled date) a message is displayed in red that is shown next to the next run date to indicate the Job's schedule is suspended until the dependency rule is satisfied. If you put the cursor over the suspend message, a tool-tip will indicate which dependency rule(s) are suspending this Job from running.

There are two general types of Dependency Rules: Static and Dynamic. A static Dependency Rules (DR) is least interesting. With a static DR, a Job can be restricted from running for a particular time range. To accomplish this, simple create the DR (from with in the Dependecy Rules tab under System Admin tool) and define a "static" time window for when a Job can and can't be run. This static DR overrides the Job Scheduler and can prevent any Job, that is associated to it, from being scheduled until its static DR window is over.

Dynamic DRs are more interesting. They are simply DRs where the Jobs themselves use the DR Java API to dynamically adjust the time window for when the DR can allow or deny a Job's schedule. Here is an example:

Here is how you would use Dependency Rules to solve this problem:

  1. Create job A and schedule it to run at 5:00AM
  2. Create a new dependency rule, called for example, "depA" (use Sys Admin tool to create a new rule)
  3. Schedule job B to start at 5:00AM
  4. Associate job B with dependency rule "depA"

Now when job A runs and completes successfully, have it make the following calls in your Tasklet code like this:

JobDependencyRule depRule = jobContext.getWorkflowContainer().getDependencyRule("depA");
depRule.setJobSchedulingAllowed(T1, T2);

When job A completes its work successfully, it should now make the calls as shown above, job B will now be able to run between times T1 and T2. Normally this is some window of time that you can define. Setting T1 and T2 to null makes the window infinite (past and future).

T1 and T2 are the range of time in which job B is allowed to run. Normally, you would make T1 equal to the current time and T2 for some time in the future where job B can be schedule to run within. In this case, it can be a few minutes or hours (up to you). So T2 might be the current time plus 30 minutes, for example.