cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1275
Views
0
Helpful
16
Replies

How to setup two Job groups mutually exclusive in TES?

phardage
Cisco Employee
Cisco Employee

I have two Job groups JG1 and JG2 and my requirement is to make sure that both Job groups must be mutually exclusive.

Please suggest. 

16 Replies 16

One possibility :

Create a public variable, a Boolean/number variable where let's say 0 means true and 1 means false. Let variable name be hasOtherRun which is initialized to 2.

Set a variable dependency on both JG1 and JG2, where the JGs will only run if hasOtherRun = 1.

Within each JG, the first job should set the value of hasOtherRun = 0

Remember to reset hasOtherRun = 2 at the end or start of the day, so the logic works daily

You will need to decide how to handle/gracefully complete the second job group that ends up waiting on dependencies the whole day.

You may consider the first run job group setting the status of second(waiting) job group to 'completed normally'

We have a scenario like this,

 

start

end

Exp1

10 PT

11:30 PT

Exp2

11:00 PT

 

HC1

11:10 PT

 

Since EXP1 is not completed both[EXP2 & HC1] is waiting for EXP1 to re set the variable.

In this case, after 11:30 PT,Exp2 and HC1 both are eligible to run which again is not as per requirement.

Please suggest.

So, is Exp2 and HC1 dependent on any output from Exp1 ? is there any logic involved in deciding which of Exp2 or HC1 needs to run ?

It would be easier if you can provide entire scenario at once

Can also consider usage of queue(with limit 1) if you want to make sure only Exp2 or HC1 runs at a given time

There is no dependency between Exp2 and HC1 output. Exp1 and Exp2 are 2 instances of Exp job group and HC1 is the first instance of job group HC1.

If we set queue limit as 1, then only one job group and all the jobs under it can run?

Hi phardage,

Alternatively, you can simply define a resource. Set the resource = 1 and add it into each of your job-level definitions (Exp1, Exp2, HC1, etc.) but not at the job group level. This is to allow for mutual exclusion, where a single job can run at any given time.

BR,

Derrick Au

Hi Derrick,

Using Virtual resource at job level can cause a job of another job group instance to run.

We cannot guarantee that all the jobs under a job group are completed before triggering a job of another job group instance.

Thanks

Pavan. 

Hi Pavan,

I see. Fortunately, there is still a way. Let's combine Dinesh's suggestion on variables and combine that with using a virtual resource. A hybrid approach might do the trick. Below are the steps to set up mutual exclusion between 2 or more job groups, please give the below a try:


Step 1. Create variable EXPVAR and initialize value = 0
Step 2. Create variable HCVAR and initialize value = 0
Note, 0 = not running state and 1 = running state
Step 3. Create a resource rsc_EXPHC and set value = 1 to ensure that only one job can run at any given time
Step 4. Create a variable action to set HCVAR = 1
Step 5. Create a job event when job is ACTIVE, and associate it with variable action created in step 4
Step 6. Create a variable action to set HCVAR = 0
Step 7. Create a job event when job completes NORMALLY, and associate it with variable action created in step 6
Step 8. Create a variable action to set EXPVAR = 1
Step 9. Create a job event when job is ACTIVE, and associate it with variable action created in step 8
Step 10. Create a variable action to set EXPVAR = 0
Step 11. Create a job event when job completes NORMALLY, and associate it with variable action created in step 10
Step 12. ADD resource rsc_EXPHC to the first children job of both EXP and HC groups
Step 13. ADD job events to the first children job of both EXP and HC groups
For example, assign job event created in step 5 to HC1, and assign job event created in step 9 to EXP1
Step 14. ADD variable dependencies
For example, in HC1 job definition, add variable dependency when EXPVAR = 0; and in EXP1 job definition, add variable dependency when HCVAR = 0
Step 15. ADD variable dependencies to subsequent jobs
For example, in HC2 job definition, add variable dependencies when HCVAR = 1 AND EXPVAR = 0, do the same for HC3, HC4, ..., HCn
in EXP2 job definition, add variable dependencies when EXPVAR = 1 AND HCVAR = 0, do the same for EXP3, EXP4, ..., EXPn
Step 16. ADD job events to the last childen job of both EXP and HC groups
For example, assign job event create in step 6 to HCn, and assign job event created in step 11 to EXPn

And lastly, reset variable back to 0 in order to prepare for the next run.

BR,

Derrick Au

Hi Derrick,

Thanks for your suggestions.

But as I said earlier, the job groups are triggered on adhoc basis and don't have a proper scheduled HC1,HC2,HC3, HC4, ..., HCn or EXP1,EXP2,EXP3, EXP4, ..., EXPn for which I can add variable dependency as explained.

Also, adding virtual resource at the first job can only control the first job of each job group. But that doesn't stop other remaining jobs running in parallel. 

Regards

Pavan.

Hi Pavan,

Whether it is HC2 or HC3 or HC4 that gets inserted first (EXP2 or EXP3 or EXP4), then a single virtual resource should be defined in ALL HC and EXP jobs. So whichever job gets inserted first, the virtual resource will help set the stage to see which group will have exclusive rights to run. For example, if HC1 gets inserted first, it will use the virtual resource to prevent EXP1 from running, and vice versa. When HC# runs it will set the variable EXPVAR = 0 and this will prevent adhoc EXP jobs from running as EXP jobs will be waiting on dependencies (EXPVAR= 1); and when EXP# runs it will set the variable HCVAR = 0 and this will prevent adhoc HC jobs from running as they will be waiting on dependencies (HCVAR=1).

BR,

Derrick Au

Hi Derrick,

Wouldn't queue work as well to ensure that only one of the HC* or EXP* are running at a given time?

Hi Dinesh,

The queue would not work in this case because say for example an HC job gets inserted first. ALL HC jobs should be able to run first before any of the EXP jobs run, and vice versa. Creating a separate queue and setting that limit to 1 is just another way to ensure that only one job can run at any given time, but this does not guarantee exclusive rights to a job group. Consider this order of adhoc job insertion, HC3, EXP2, HC4, EXP5, etc. The queue will only run these jobs first in-first out fashion with some slight control over the priority of jobs, but in order to mimic mutual exclusion between job groups, a hybrid approach combining variables and resource should work.

BR,

Derrick Au

Thinking about this some more, ADDING the virtual resource to all jobs will not work because as soon as the resource becomes available then it may get passed over to another job group. Another way, is to create 2 starter jobs: EXP_StarterJob and HC_StarterJob. A single virtual resource would be added into each of these starter jobs, so that only one starter job can run. When the starter job becomes active it will call a job action to instantiate a job group and launch those jobs.

Also, the frequency can be controlled at the job group level to {Skip, or Run Anyway} and at the job children level if job is running then: {Skip, Run Anyway, Defer until Complete, and Defer until Normal}

BR,

Derrick Au

Hi Derrick,

EXP_StarterJob and HC_StarterJob cannot hold the virtual resource for longer as it would just be triggering the job group.

Also cannot confirm on the exact sleep x seconds as it is hard to confirm how long the jobs under job group might run.

Thanks

Pavan.

Hi Pavan,

The virtual resource should be placed in the starter jobs. Because the resource limit is defined = 1, that means ONLY ONE starter job will trigger the job group. We want to have the starter job run a benign command like sleep for X seconds, where X seconds can be as little as 30 seconds or 60 seconds in order to hold on to that resource. So as long as the starter job with the resource is active, this will set the other variables so that the other job group dependent on these variables will NOT run until the job group that triggered first completes normally.

BR,

Derrick Au

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: