Quartz.net Scheduler is working on local while debugging but not on production

送分小仙女□ 提交于 2019-12-25 14:39:12

问题


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();


来源:https://stackoverflow.com/questions/43820464/quartz-net-scheduler-is-working-on-local-while-debugging-but-not-on-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!