在将Hangfire(v1.7.7)设置为always run之后,所有重复出现的作业将在重新启动IIS或回收池后立即执行。这是不受欢迎的行为,因为我们计划将作业每月一次或每周运行一次,并且每次部署都会使它们运行。
我们无法在文档或论坛中找到配置属性来防止此行为,我们仍在分析存储库,试图寻找线索。
我们发现this issue和this discussion与我们的问题有关。
除了上面提供的链接之外,它代表我们为使Hangfire始终运行而进行的确切配置,这是我们当前的配置:
private BackgroundJobServer _backgroundJobServer;
app.UseHangfireDashboard("/hangfire",new DashboardOptions
{
Authorization = new[] { new HangfireRestrictiveAuthorizationFilter() },StatsPollingInterval = UM_MINUTO_EM_MILISEGUNDOS * 10
});
GlobalConfiguration.Configuration.UseSqlServerStorage("Implanta",new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),SchemaName = "HangFireSiscaf",SlidingInvisibilityTimeout = null
});
_backgroundJobServer = new BackgroundJobServer(new BackgroundJobServerOptions()
{
Queues = new[] { "siscaf" },ServerName = "SISCAF.NET",WorkerCount = 5
});
这就是我们通常安排定期作业的方式(几个方法名称和字符串写在pt-BR中):
RecurringJob.AddOrupdate<ColetaMensalCFATask>(
ColetaMensalCFATask.Key,x => x.Executetask(),Cron.Monthly(diaAgendamentoMensalColetaCFA,timeSpanHoraAgendamentoMensalColetaCFA.Minutes),TimeZoneInfo.Local,"siscaf");
更新1: 通过删除作业执行历史记录并将每个作业添加为新作业,我们能够重现所需的行为。但是,这不是令人满意的解决方案。