问题描述
是否有一种方法可以每隔几秒钟设置一次hangfire周期性作业?我不寻求解决方案,即一劳永逸"任务会产生另一个一劳永逸"任务,如果没有,建议的替代方法是什么?
Is there a way to set hangfire recurring jobs every few seconds?I do not seek a solution where fire and forget task creates another fire and forget task, and if not, what are suggested alternatives?
推荐答案
不确定何时支持该功能,但已在带有Hangfire 1.7.0的ASP.NET Core 2.0中进行了尝试.以下代码每20秒调度一次作业:
Not sure when this became supported but tried this in ASP.NET Core 2.0 with Hangfire 1.7.0. The following code schedules a job every 20 seconds:
RecurringJob.AddOrUpdate<SomeJob>(
x => x.DoWork(),
"*/20 * * * * *");
如果我没记错的话,由于Hangfire使用 NCrontab 允许cron表达式具有6个标记(第二个粒度而不是分钟的粒度).
If I am not mistaken 6 tokens (as opposed to standard 5 tokens) is supported due to Hangfire use of NCrontab which allows cron expressions with 6 tokens (second granularity instead of minute granularity).
Hangfire仪表板还很好地显示了运行之间的较小时间间隔:
Hangfire dashboard also nicely shows the small time interval between runs:
这篇关于不到一分钟的Hangfire重复执行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!