I want to implement the Quartz.Net
in my C#.Net project. I am syncing 1 FTP and downloading all file every 10 minutes. Once I downloaded every file, I am going to process them all. If there are be more files, it will take more time than 10 minutes.
How to run 1 instance of a job and, if the trigger sets off any another job instance, it should not run and dispose it?
My Code:
Quartz Scheduler 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 Job 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;
}
}