How can I set priorities to quartz trigger? - quartz-scheduler

I am using Quartz Scheduler and there are 15 jobs. For each job there is one trigger.
I want to set priority for each trigger. I can set low priority as 10 and high priority as 1.
But as I am having 15 triggers for 15 jobs I need different priority for each trigger.
e.g trigger1 will have priority 10, trigger2 will have priority 9.
In this way I need to give same priority for two triggers.
So if two triggers with same priority will get execute at same time then which trigger will execute first?
Can anyone tell me how I can set different priorities for different triggers?

Trigger have a property called WithPriority which takes a integer value. When multiple triggers are fired at the same time the scheduler will fire the trigger with the highest priority first. And if the two triggers have same priority then either trigger will get fired.
.WithPriority(15) will run first
.WithPriority(1) will be the last trigger

Triggers have a 'priority' property on them. Just set the property accordingly as the triggers are created, or use the api to retrieve the triggers, set the priorities, and reschedule them.
If two or more triggers have the same fire time and same priority, one will be randomly chosen for firing first (what else could the ordering be based on?).

Related

What is the behavior of ADF schedule triggers when a schedule starts before the previous one ends?

I am trying to contrast and find the exact behavior of ADF schedule triggers and ADF thumbing window triggers when a trigger starts before the previous pipeline triggered by the schedule ends?
For example, let’s say we have a every 5 min schedule but the pipeline takes one hour to finish. What happens to all the every-5-min triggers that happen until the pipeline is finished?
Are the behaviors of thumbing window and schedule triggers the same in this scenario?
When using the ADF schedule trigger (shorter recurrence time than the amount of time pipeline takes to execute), the pipeline starts executing (In progress state) every time it is triggered irrespective of the previous pipeline run status.
Using the trigger with 3-minute recurrence interval produced the following output.
The tumbling window trigger reacts in the same way as a schedule trigger. The pipeline starts execution irrespective of the status of previous run. The trigger used has a 5-minute recurrence interval.
So, in this scenario both types of triggers behave in the same way. But tumbling window triggers have a self-dependency property which is not available with Schedule triggers. If the consecutive pipeline runs depend on each other, the self-dependency property can be used. Other significant differences between these triggers, including the self-dependency property are mentioned in the following Microsoft Q&A link.
https://learn.microsoft.com/en-us/answers/questions/207405/when-to-use-tumbling-window-type-trigger.html

Azure Data Factory ADFV2 Trigger Overlap

I have a ADFV2 trigger that runs every 2 minutes. The pipeline that is called usually takes just over a minute to run but sometimes it takes over 2 minutes but if that happens the trigger kicks in again and runs regardless of the previous trigger still running or not. Is there any way to stop this overlap?
The trigger needs to run every 2 minutes.
Thanks.
There is a concurrency setting in the pipeline definition. Set it to 1. The trigger will create an event, but it will be set to Queued state until previous job completes

Quartz scheduler: Register multiiple jobs under same trigger

I'm new to the Quartz scheduler. I had few queries and hope someone give a hand here. Thanks a lot!
First of all, let me share with you on my way to organize the jobs and triggers in single Scheduler:
One trigger group, many triggers with unique name
Many job groups, many jobs with unique name inside one group
One job group may associate with one trigger so that all jobs under this group will be fired at the same time
I think this organization is quite normal in scheduler software. However, I only found references to register same job with multiple triggers. Even though, I still thought to register many jobs with the same trigger is achievable logically.
Following is my own logic to achieve the goal:
Job A be created, Trigger A be created, call function scheduleJob(JobA, TriggerA) to register Job A with Scheduler firstly
Job B be created, get Trigger A from Scheduler based on its unique name, call function scheduleJob(JobB, TriggerA) to register Job B with Scheduler later
Therefore, refer to my own logic, I had two queries:
Is it possible to implement getting Trigger A from Scheduler based on its name ?
Is it a correct way to register multiple jobs with same trigger by using scheduleJob() function again and again ?
No, a job can have many triggers relating to it, but a trigger can only relate to one job. Though you can get something of the effect you're after if you use a job/trigger listener and schedule triggers to fire other jobs immediately when the one trigger fires.
You can set up multiple identical triggers, one for each job.

Quartz.net scheduler and IStatefulJob

I am wondering if I am understanding this right.
http://quartznet.sourceforge.net/apidoc/
IStatefulJob instances follow slightly
different rules from regular IJob
instances. The key difference is that
their associated JobDataMap is
re-persisted after every execution of
the job, thus preserving state for the
next execution. The other difference
is that stateful jobs are not allowed
to Execute concurrently, which means
new triggers that occur before the
completion of the IJob.Execute method
will be delayed.
Does this mean all triggers will be delayed until another trigger is done? If so how can I make it so only the same triggers will not fire until the previous trigger is done.
Say I have trigger A that fires every min but for some reason it is slow and takes a minute and half to execute. If I just use a plan IJob the next one would fire and I don't want this. I want to halt trigger A from fireing again until it is done.
However at the same time I have trigger B that fires every minute as well. It is going normal speed and finishes every minutes on time. I don't want trigger B to be held up because of trigger A.
From my understanding this is what would happen if I use IStatefulJob.
In short.. This behavior is from job's side. So regardless how many triggers you may have only single instance of given IStatefulJob (job name, job group dictates the instance id) running at a time. So there might be two instance of same job type, but no same-named jobs (name, group) if job implements IStatefulJob.
If trigger misses its fire time because of this, the misfire instructions come into play. A trigger that misses its next fire because the earlier invocation is still running decides what to do based on its misfire instruction (see API and tutorial).
With plain IJob you have no guarantees about how many jobs will be running at the same time if you have multiple triggers for it and/or misfires are happening. IJob is just contract interface for invoking the job. Quartz.NET 2.0 will split IStatefulJob combined behavior to two separate attributes: DisallowConcurrentExecution and PersistJobDataAfterExecution.
So you could combine same job type (IStatefulJobs) with two definitions (different job names) and triggers with applicable misfire instructions.

how to make multiple instances execute the same job at the same time not concurrently

I have 4 instances of Quartz Server. All of the instances point to one ADO JobStore. All I want to do is to make each Quartz instance execute the same job at the same time.
I hope it's clear enough.
This isn't supported out of the box. Whenever a trigger fires, it can only be consumed by one instance. You could fire 4 triggers, but it is not guaranteed that the job will not run twice on one instance.
If you want each instance to fire the job once, then you will have to set up 4 separate job stores.
What I do (in Quartz.NET 2.4.1) is that I have multiple identical scheduler instances, which only differ in scheduler instance name (quartz.scheduler.instanceName). They register identical jobs and triggers. Because of different scheduler instance names, the jobs and triggers are duplicated in the job store (scheduler name is part of the primary key in every table of JobStoreTX). This causes logically the same triggers to fire on all scheduler instances at the same time. They are actually separate triggers, though, so each will handle misfires etc separately.