如何在 Quartz.Net 调度程序中完成当前作业后立即将作业调度到 运行?
How can I schedule a job to run immediately after current job complete in Quartz.Net Scheduler?
我有一个 EventJob
class 派生自 IJob
和 EventScheduler
class 用于配置我的工作。
public class EventJob : IJob
{
public void Execute(IJobExecutionContext context)
{
//some code...
}
}
public class EventScheduler
{
public ITrigger GetEventTrigger()
{
DateTimeOffset startTime = DateBuilder.FutureDate(2, IntervalUnit.Second);
//Time Scheduling Setting
ITrigger eventTrigger = TriggerBuilder.Create()
.WithIdentity("EventTrigger")
.StartAt(startTime)
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
.Build();
return eventTrigger;
}
public IJobDetail GetJobDetail()
{
//Job Definition Setting
IJobDetail eventJob = JobBuilder.Create<EventJob>()
.WithIdentity("EventJob")
.Build();
return eventJob;
}
}
因此,我需要在使用 [DisallowConcurrentExecution]
配置完成当前作业后立即添加 运行 的其他作业。
我该怎么做?
您可以通过使用 IStatefulJob 来实现此目的 - 运行 这两个作业都具有您想要的间隔,并且不会 运行 同时进行。
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.
经过一番调查,我终于找到了实现此目标的好方法。
@Vishal 在How to do “sequential” Job Scheduling (Quartz?)
中描述
我有一个 EventJob
class 派生自 IJob
和 EventScheduler
class 用于配置我的工作。
public class EventJob : IJob
{
public void Execute(IJobExecutionContext context)
{
//some code...
}
}
public class EventScheduler
{
public ITrigger GetEventTrigger()
{
DateTimeOffset startTime = DateBuilder.FutureDate(2, IntervalUnit.Second);
//Time Scheduling Setting
ITrigger eventTrigger = TriggerBuilder.Create()
.WithIdentity("EventTrigger")
.StartAt(startTime)
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
.Build();
return eventTrigger;
}
public IJobDetail GetJobDetail()
{
//Job Definition Setting
IJobDetail eventJob = JobBuilder.Create<EventJob>()
.WithIdentity("EventJob")
.Build();
return eventJob;
}
}
因此,我需要在使用 [DisallowConcurrentExecution]
配置完成当前作业后立即添加 运行 的其他作业。
我该怎么做?
您可以通过使用 IStatefulJob 来实现此目的 - 运行 这两个作业都具有您想要的间隔,并且不会 运行 同时进行。
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.
经过一番调查,我终于找到了实现此目标的好方法。
@Vishal 在How to do “sequential” Job Scheduling (Quartz?)
中描述