问题描述
我在 Quartz 中设置了一些作业以按设定的时间间隔运行.问题是,当服务启动时,它会尝试立即启动所有作业……有没有办法使用 .xml 配置为每个作业添加延迟?
I have a few jobs setup in Quartz to run at set intervals. The problem is though that when the service starts it tries to start all the jobs at once... is there a way to add a delay to each job using the .xml config?
以下是 2 个作业触发器示例:
Here are 2 job trigger examples:
<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>
如您所见,有 2 个触发器,第一个每天重复,下一个每天重复两次.
As you see there are 2 triggers, the first repeats every day, the next repeats twice a day.
我的问题是我希望第一个或第二个工作在另一个之后开始几分钟......(因为它们最终都访问相同的 API,我不想使请求过载)
My issue is that I want either the first or second job to start a few minutes after the other... (because they are both in the end, accessing the same API and I don't want to overload the request)
是否有重复延迟或优先级属性?我找不到任何这样说的文档..
Is there a repeat-delay or priority property? I can't find any documentation saying so..
推荐答案
我知道您是通过 XML 执行此操作,但是在代码中您可以将 StartTimeUtc
设置为像这样延迟 30 秒...
I know you are doing this via XML but in code you can set the StartTimeUtc
to delay say 30 seconds like this...
trigger.StartTimeUtc = DateTime.UtcNow.AddSeconds(30);
这篇关于Quartz.Net - 延迟一个简单的触发器启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!