当 Quartz.NET/Quartz 发生什么时

发布于 2024-09-28 17:41:33 字数 92 浏览 4 评论 0原文

...当下一个执行时间发生时作业仍在执行?

例如,如果我有一个每 30 秒发生一次的作业,并且 30 秒后它仍在运行,那么下一个实例会发挥作用还是会等待?

...when a job is still being executed when its next execution time occurs?

For example, if I have a job that occurs every 30 seconds, and after the 30 seconds it is still operating, would the next instance come into play or would it wait?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天荒地未老 2024-10-05 17:41:33

简短的答案是,将执行一项新作业,除非您继承自 IStatefulJob,在这种情况下,一次只允许运行一个作业实例。

The short answer is that a new job will be executed, unless you are inheriting from IStatefulJob, in which case only one job instance is allowed to run at a time.

浅笑依然 2024-10-05 17:41:33

正如 TskTsk 回答的那样,您可以实现 IStatefulJob 而不是 IJob,但有一个问题!如果您的作业执行时间超过 30 秒(因此您有一个或多个作业正在等待该作业完成),则在其执行后,所有正在等待的作业将立即触发!为了克服这个问题,您需要创建实现 SimpleTrigger 的新类。这个新的触发器类应该重写 GetFireTimeAfter。

public class MyTrigger : SimpleTrigger
{

    public MyTrigger(string name,
                     string group,
                     DateTime startTimeUtc,
                     DateTime? endTimeUtc,
                     int repeatCount,
                     TimeSpan repeatInterval) : base(name, startTimeUtc, endTimeUtc, repeatCount, repeatInterval)
    {
    }

    public override DateTime? GetFireTimeAfter(DateTime? afterTimeUtc)
    {
        return DateTime.UtcNow.AddSeconds(RepeatInterval.TotalSeconds);
    }

}

这样第一个作业完成后就不会立即执行下一个作业。

As TskTsk answered, you can implement IStatefulJob insted of IJob but there is a catch! If you are having job that is executing more than 30 seconds (thus you have on or more jobs waiting this one to finish), after its execution all jobs that were waiting will fire immidietly! To overcome this you need to create new class that implements SimpleTrigger. This new trigger class should have overriden GetFireTimeAfter.

public class MyTrigger : SimpleTrigger
{

    public MyTrigger(string name,
                     string group,
                     DateTime startTimeUtc,
                     DateTime? endTimeUtc,
                     int repeatCount,
                     TimeSpan repeatInterval) : base(name, startTimeUtc, endTimeUtc, repeatCount, repeatInterval)
    {
    }

    public override DateTime? GetFireTimeAfter(DateTime? afterTimeUtc)
    {
        return DateTime.UtcNow.AddSeconds(RepeatInterval.TotalSeconds);
    }

}

This way the next job will not execute immidietly after first one is finished.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文