Quartz.NET正在运行作业自动重新计划? [英] Quartz.NET Running Job Self-Reschedule?

查看:178
本文介绍了Quartz.NET正在运行作业自动重新计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完全以编程方式创建了Quartz.NET作业(无配置文件等)。它按计划运行良好。使用cron字符串初始化作业,以每5分钟运行一次。我想让工作根据环境更改自身的时间表(例如,错误会随着时间发生,因此cron应该更改为30分钟)。

I have created a Quartz.NET job completely programmatically (no config file, etc). It runs on-schedule fine. The job is initialized with a cron string to run every 5 minutes. I would like to have the job change the schedule of itself based on the environment (eg errors happen over time so cron should change to 30 minutes).

确定在

protected override void ExecuteInternal( IJobExecutionContext context )

方法,因此工作会改变。我是否要在context.Scheduler属性中进行设置?我是否必须去调度程序本身并终止工作并重新创建它(虽然听起来有点沉重)?

method so the job "changes itself". Do I set something in the context.Scheduler property? Do I have to go to the Scheduler itself and terminate the job and re-create it (sounds kind of heavy handed to me though)?

感谢所有想法,谢谢。

All ideas appreciated, thanks.

推荐答案

skarist使我走上了正轨。

skarist put me on the right track. Including my findings here for the next kid that runs into this.

protected override void ExecuteInternal( IJobExecutionContext jobContext )
{
    // ... do work...
    var tnew = new CronTriggerImpl( #nameofcurrentlyrunningjob# )
    {
        CronExpressionString = "my new cron string is here" ,
        TimeZone = TimeZoneInfo.Utc
    };

    var jobNew = new JobDetailImpl( #nameofcurrentlyrunningjob# , typeof( CurrentJobType ) );

    jobContext.Scheduler.RescheduleJob( new TriggerKey( #nameofcurrentlyrunningjob# ) , tnew );
}

我还向该类添加了[DisallowConcurrentExecution]属性,但这并不直接相关

I also added the [DisallowConcurrentExecution] attribute to the class but that's not directly related.

这篇关于Quartz.NET正在运行作业自动重新计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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