Schedule multiple scheduled tasks using Quartz.net

718 Views Asked by At

I'm trying to set up 2 and more scheduled tasks to run 4 hours difference since when the first task stared. To do so I'm using Quartz.NET library like following:

ITrigger firstTrigger = TriggerBuilder.Create()
                     .WithIdentity("Trigger1")
                     .StartNow()
                     .WithCronSchedule("0 0 0/4 * * ?")
                     .ForJob("Job1")
                     .Build();

IJobDetail secondJob = JobBuilder.Create<StoreAnalyticsUsersUpdate>()
               .WithIdentity("Job2")
               .Build();

ITrigger secondTrigger = TriggerBuilder.Create()
                 .WithIdentity("Trigger2")
                 .StartAt(DateTimeOffset.UtcNow)
                 .WithCronSchedule("0 0 0/4 * * ?")
                 .ForJob("Job2")
                 .Build();

ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sc = sf.GetScheduler();
sc.ScheduleJob(firstJob, firstTrigger);
sc.ScheduleJob(secondJob, secondTrigger);
sc.Start();

I've wrote this code for testing purposes, just to see if the tasks'll run properly. Turns out neither one of the scheduled tasks after I run my application...

P.S. I call the method at Global.asax class so that's not the issue...

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    JobScheduler.StartCompetitorResearchUpdate(); // this is the method for the above code
}

What am I doing wrong here?

1

There are 1 best solutions below

2
On

in

.StartAt(DateTimeOffset.UtcNow).WithCronSchedule("0 0 0/4 * * ?").ForJob("Job2").Build();

Test with

.StartAt(DateTimeOffset.UtcNow).WithCronSchedule("0 0 0/4 * * ?").ForJob(secondJob).Build();