Dependency Rules

From the System Administration tool you can create, edit, and view all the Dependency Rules available in your JobServer. Dependency Rules are a feature that allow one Job to affect the scheduling rules of other Jobs. This tool allows you to create and edit Dependency Rules. Using the Job Scheduler tool you can then associate a Job to one or more Dependency Rules.

A Dependency Rule has two primary states:

When the rule is in an "allowed" state, the Jobs that are associated to the rule can only run if their next run date lies between the start and end dates for the Dependency Rule. An empty start and/or end date means that their is no date restriction on the the dependency rule and thus the rule extends to infinity. That means an empty/null start date means infinity into the past and an empty/null end date means infinity into the future.

Dependency Rules typically work by having one Job that can alter the start and end dates of a Dependency Rule to either prevent or allow Jobs that are associated to the rule from running or not. It is a very powerful feature and can be used in a variety of scenarios. For example, if you have Job A that runs every morning and Jobs B and C that must not run until Job A completes even if their scheduled times arrives. This works by having Job A change the start and end dates on the Dependency Rule after it is finished its run. Job A is not associated to the Dependency Rule directly, it only edits the start and end dates of the corresponding Dependency Rule when it runs. Jobs B and C are associated to the Dependency Rule. So the Scheduler will prevent them from running until the Dependency Rule allows them to run. This in turn make them dependent on Job A.

Here is one example scenario where Dependency Rules can be used: 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. Many other scenarios are possible with Dependency Rules and the support Tasklet API.