I am very new to using quartz and I have a question about triggers. Is it possible to run based on the existence of a file? I would like Quartz to do the job until a specific file is found, and then stop doing this job and maybe move on to another.
For example, I would like to do something like this:
(1) Job1 checks if File.txt exists in this directory every 60 seconds.
(2) If File.txt is found, run Job2 to start. Job1 stops checking for a file.
Now I have:
var Job1 = JobBuilder.Create<TestEmail>().WithIdentity("job1", "group1").Build();
var Job2 = JobBuilder.Create<TestFileTrigger>().WithIdentity("job2", "group2").Build();
ITrigger trigger1 = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1").StartNow()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever())
.Build();
ITrigger trigger2 = TriggerBuilder.Create()
.WithIdentity("trigger2", "group2").StartNow()
.Build();
scheduler.ScheduleJob(Job1, trigger1);
if (TestFileTrigger.fileExistence == true)
{
scheduler.ScheduleJob(Job2, trigger2);
}
but it looks like Job2 never starts.
TestEmail TestFileTrigger . TestFileTrigger.fileExistence ( ).
:
TestFileTrigger.fileExistence . Job1/Job2, .
:
, Thread.Sleep(TimeSpan.FromSeconds(x)); if, if , . ( x - .) , ? , .