【问题标题】:Quartz.NET StartNow not working together with WithDailyTimeIntervalScheduleQuartz.NET StartNow 不能与 WithDailyTimeIntervalSchedule 一起使用
【发布时间】:2017-08-23 14:55:14
【问题描述】:
            ITrigger trigger = TriggerBuilder.Create()
                                .WithIdentity("trigger1", "group1")
                                .WithDailyTimeIntervalSchedule(x => x
                                    .WithIntervalInHours(2)
                                    .OnEveryDay()
                                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 0))
                                    .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(23, 00)))
                                .StartNow()
                                .Build();

上述代码的问题是StartNow 不起作用。它运行正常,但仅在 2 小时后运行。我不能立即运行它。

StartNow 正在与 WithSimpleSchedule 合作,但不与 .WithDailyTimeIntervalSchedule 合作

【问题讨论】:

    标签: c# quartz.net


    【解决方案1】:

    看起来WithDailyTimeIntervalSchedule 不是您需要的。如果您指定开始时间 = 上午 8 点,结束时间 = 晚上 11 点,间隔 = 2 小时,则作业将被安排在上午 8 点、上午 10 点、下午 12 点、下午 2 点、下午 4 点、下午 6 点、晚上 8 点和 10 点运行下午。

    作为一种解决方案,您可以创建两个触发器:

    1. 如果当前时间在上午 8 点到晚上 11 点之间,请创建现在触发、现在 + 2 小时、现在 + 4 小时并在今天晚上 11 点停止的触发器。
    2. 从下一个上午 8 点(今天或明天)开始,第二个触发器将在上午 8 点、上午 10 点等触发。

    【讨论】:

    • 是的,这是临时解决方案。我只有 1 个 WithSimpleSchedule 的工作/触发器,我检查它是否在 8-11 之间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 2017-04-14
    • 2016-09-16
    • 2016-04-19
    • 1970-01-01
    • 2011-01-19
    相关资源
    最近更新 更多