I have a job scheduled by Quartz in ASP.NET Core to run every 15 minutes.
I want to run it initially (force Quartz to start now).
I use the following code but it doesn't run the job initially and waits for 15 min to start.
It seems like .StartNow()
is not working?
public class JobSchedulerSimple
{
public static async Task StartSimpleSync()
{
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = await sf.GetScheduler();
IJobDetail job = JobBuilder.Create<FileJob>()
.WithIdentity("ID", "ID")
.Build();
ITrigger trigger = TriggerBuilder.Create().WithIdentity("StartSimpleSync", "ID")
.StartNow()
.WithCronSchedule("0 0/15 * * * ?")
.Build();
await sched.ScheduleJob(job, trigger);
await sched.Start();
}
}
CodePudding user response:
You can call await sched.TriggerJob(job.Key);
this will create a simple trigger with immediate fire time and run once behavior under the hood.
For cron trigger StartNow()
just means the start of calculation of fires, it still will follow the schedule which is not "right now".