-->

Quartz.net Scheduler is working on local while deb

2019-09-14 11:05发布

问题:

I have used Quartz.net for scheduling some task. The problem is that it's working only while debugging in the local.

The code is not working on my local server and production as well.

Please don't mark it as duplicate because none of the solution mentioned in other questions solved my issue.

 public class JobScheduler
{
    public static ISchedulerFactory schedFact;
    public static IScheduler sched;

    public static void Start()
    {
        schedFact = new StdSchedulerFactory();
        // get a scheduler
        sched = schedFact.GetScheduler();
        sched.Start();

        IJobDetail job = JobBuilder.Create<RemovePlanJob>().Build();

        int hours = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["schedulerHours"].ToString());
        int minute = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["schedulerMinutes"].ToString());

        ITrigger trigger = TriggerBuilder.Create()
                            .WithDailyTimeIntervalSchedule
                              (s =>
                                 s.WithIntervalInHours(24)
                                .OnEveryDay()
                                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(hours, minute))
                              )
                            .Build();

        sched.ScheduleJob(job, trigger);

    }
}

public class RemovePlanJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        //execute code
    }
}

Any Help would be great!!

回答1:

I got it working by adding timezone in TriggerBuilder.

 ITrigger trigger = TriggerBuilder.Create()
                            .WithDailyTimeIntervalSchedule
                              (s =>
                                 s.WithIntervalInHours(24)
                                .OnEveryDay()
                                .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(hours, minute))
                                .InTimeZone(TimeZoneInfo.Local)
                              )
                            .Build();