Quartz.Net - delayed launch of a simple launch

I have several jobs in Quartz to run at given intervals. The problem is that when the service starts, it tries to start all jobs right away ... is there a way to add a delay to each job using .xml config?

Here are two examples of a job trigger:

 <simple>
    <name>ProductSaleInTrigger</name>
    <group>Jobs</group>
    <description>Triggers the ProductSaleIn job</description>
    <misfire-instruction>SmartPolicy</misfire-instruction>
    <volatile>false</volatile>
    <job-name>ProductSaleIn</job-name>
    <job-group>Jobs</job-group>
    <repeat-count>RepeatIndefinitely</repeat-count>
    <repeat-interval>86400000</repeat-interval>        
  </simple>

 <simple>
    <name>CustomersOutTrigger</name>
    <group>Jobs</group>
    <description>Triggers the CustomersOut job</description>
    <misfire-instruction>SmartPolicy</misfire-instruction>
    <volatile>false</volatile>
    <job-name>CustomersOut</job-name>
    <job-group>Jobs</job-group>
    <repeat-count>RepeatIndefinitely</repeat-count>
    <repeat-interval>43200000</repeat-interval> 
  </simple>

As you can see, there are two triggers, the first repeats every day, the next repeats twice a day.

My problem is that I want either the first or second task to start a few minutes after the other ... (because they are both at the end, accessing the same API, and I do not want to overload the request)

Is there a delay or priority property? I can not find documentation saying so.

+3
3

, XML, StartTimeUtc 30 , ...

trigger.StartTimeUtc = DateTime.UtcNow.AddSeconds(30);
+3

This is not a perfect answer for your XML file, but with the code, you can use the StartAt extension method when creating a trigger.

/* calculate the next time you want your job to run - in this case top of the next hour */
var hourFromNow = DateTime.UtcNow.AddHours(1);
var topOfNextHour = new DateTime(hourFromNow.Year, hourFromNow.Month, hourFromNow.Day, hourFromNow.Hour, 0, 0);

/* build your trigger and call 'StartAt' */
TriggerBuilder.Create().WithIdentity("Delayed Job").WithSimpleSchedule(x => x.WithIntervalInSeconds(60).RepeatForever()).StartAt(new DateTimeOffset(topOfNextHour))
0
source

Source: https://habr.com/ru/post/1760381/


All Articles