如何在 QuartZ 中一次 运行 一个作业实例?
How to run one instance of a job at one time in QuartZ?
我想在我的 C#.Net 项目中实现 Quartz.Net
。我每 10 分钟同步 1 FTP 并下载所有文件。下载每个文件后,我将处理所有文件。如果文件较多,则需要 10 分钟以上的时间。
如何 运行 1 个作业实例,如果触发器触发任何另一个作业实例,它不应该 运行 并处理它?
我的代码:
Quartz 调度程序 Class
public class ResponseFileSyncJobScheduler
{
public static async Task StartResponsefileSyncker()
{
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = await sf.GetScheduler();
//DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);
IJobDetail job = JobBuilder.Create<ResponseFileJob>()
.WithIdentity("ResponsefileSync", "sgroup")
.Build();
ITrigger trigger = TriggerBuilder.Create().WithIdentity("TriggerfileSync", "sgroup")
.WithDailyTimeIntervalSchedule
(s => s.WithIntervalInMinutes(10).OnEveryDay())
.StartAt(DateTime.Now.AddMinutes(1))
.Build();
await sched.ScheduleJob(job, trigger);
await sched.Start();
await Task.Delay(TimeSpan.FromSeconds(65));
}
}
Quartz 作业Class
public class QuartzJobSOGET : IJob
{
internal static readonly Task CompletedTask = Task.FromResult(true);
public virtual Task Execute(IJobExecutionContext context)
{
JobKey jobKey = context.JobDetail.Key;
//Write Date Time to File - to ensure Quartz Scheduler Working
WritetoFile(DateTime.Now.ToString());
//Sync every present file and process
//once processed delete file from server and make log,
//will take 1 min to process single file (almost)
SyncResponseFilefromSOGETftp();
return CompletedTask;
}
}
好久好久了,早找到答案了,但是不能post这里
我们可以在 class 上使用 DisallowConcurrentExecution
属性来停止单个作业的多次执行。
但是,您也可以查看此 link 以解决 Git-问题:(可能会有用)@DisallowConcurrentExecution misinterpretation on clustered Scheduler
我想在我的 C#.Net 项目中实现 Quartz.Net
。我每 10 分钟同步 1 FTP 并下载所有文件。下载每个文件后,我将处理所有文件。如果文件较多,则需要 10 分钟以上的时间。
如何 运行 1 个作业实例,如果触发器触发任何另一个作业实例,它不应该 运行 并处理它?
我的代码:
Quartz 调度程序 Class
public class ResponseFileSyncJobScheduler
{
public static async Task StartResponsefileSyncker()
{
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = await sf.GetScheduler();
//DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);
IJobDetail job = JobBuilder.Create<ResponseFileJob>()
.WithIdentity("ResponsefileSync", "sgroup")
.Build();
ITrigger trigger = TriggerBuilder.Create().WithIdentity("TriggerfileSync", "sgroup")
.WithDailyTimeIntervalSchedule
(s => s.WithIntervalInMinutes(10).OnEveryDay())
.StartAt(DateTime.Now.AddMinutes(1))
.Build();
await sched.ScheduleJob(job, trigger);
await sched.Start();
await Task.Delay(TimeSpan.FromSeconds(65));
}
}
Quartz 作业Class
public class QuartzJobSOGET : IJob
{
internal static readonly Task CompletedTask = Task.FromResult(true);
public virtual Task Execute(IJobExecutionContext context)
{
JobKey jobKey = context.JobDetail.Key;
//Write Date Time to File - to ensure Quartz Scheduler Working
WritetoFile(DateTime.Now.ToString());
//Sync every present file and process
//once processed delete file from server and make log,
//will take 1 min to process single file (almost)
SyncResponseFilefromSOGETftp();
return CompletedTask;
}
}
好久好久了,早找到答案了,但是不能post这里
我们可以在 class 上使用 DisallowConcurrentExecution
属性来停止单个作业的多次执行。
但是,您也可以查看此 link 以解决 Git-问题:(可能会有用)@DisallowConcurrentExecution misinterpretation on clustered Scheduler