我如何强制quartz.net作业完成后,重新启动INTERVALL [英] How do I force a quartz.net job to restart intervall after completion

查看:1037
本文介绍了我如何强制quartz.net作业完成后,重新启动INTERVALL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我用一个项目 TopShelf TopShelf.Quartz

I have a project where I use TopShelf and TopShelf.Quartz

这个例子我建设我的工作与

                s.ScheduleQuartzJob(q =>
                    q.WithJob(() => JobBuilder.Create<MyJob>().Build())
                    .AddTrigger(() => TriggerBuilder.Create()
                        .WithSimpleSchedule(builder => builder
                            .WithIntervalInSeconds(5)
                            .RepeatForever())
                        .Build())
                );

这激发我的工作,每五秒钟即使previous仍在运行。我真正想要的才达到的开始工作,并在完成后等待五秒钟,然后再次启动。这是可能的还是我有(通过一个静态变量为例),以实现自己的逻辑。

which fires my job every five seconds even if the previous is still running. What I really want to achive is to start a job and after the completion wait five seconds and start again. Is this possible or do I have to implement my own logic (for example via a static variable).

推荐答案

该JobListener解决方案是一个非常强大和灵活的方式完成后,重新安排你的工作。由于内特Kerkhofs和stuartd为输入。

The JobListener solution is a very powerful and flexible way to reschedule your job after completion. Thanks to Nate Kerkhofs and stuartd for the input.

在我的情况下,它足以来装饰我的作业类与 DisallowConcurrentExecution 属性,因为我没有我的工作的不同实例

In my case it was sufficient to decorate my Job class with the DisallowConcurrentExecution attribute since I don't have different instances of my job

[DisallowConcurrentExecution]
public class MyJob : IJob
{
}

FYI:使用JobListerener与 TopShelf.Quartz 的code可能看起来像这样

FYI: Using a JobListerener with TopShelf.Quartz the code could look like this

var jobName = "MyJob";
var jobKey = new JobKey(jobName);

s.ScheduleQuartzJob(q =>
           q.WithJob(() => JobBuilder.Create<MyJob>()
                .WithIdentity(jobKey).Build())
            .AddTrigger(() => TriggerBuilder.Create()
                .WithSimpleSchedule(builder => builder
                    .WithIntervalInSeconds(5)
                .Build())

var listener = new RepeatAfterCompletionJobListener(TimeSpan.FromSeconds(5));
var listenerManager = ScheduleJobServiceConfiguratorExtensions
      .SchedulerFactory().ListenerManager;
listenerManager.AddJobListener(listener, KeyMatcher<JobKey>.KeyEquals(jobKey));

如果您使用的是 TopShelf.Quartz.Ninject (像我这样做),不要忘了叫 UseQuartzNinject()在调用 ScheduleJobServiceConfiguratorExtensions.SchedulerFactory()

If you are using TopShelf.Quartz.Ninject (like I do) don't forget to call UseQuartzNinject() prior to calling ScheduleJobServiceConfiguratorExtensions.SchedulerFactory()

这篇关于我如何强制quartz.net作业完成后,重新启动INTERVALL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆