【问题标题】:Hangfire fetching database every 15 secondHangfire 每 15 秒获取一次数据库
【发布时间】:2022-01-06 11:40:44
【问题描述】:

我使用 Recurring Job 来调用我的函数 Test() 和 Cron.Daily() 。 我不需要每 15 秒获取一次数据库,我的函数每天只执行一次。

如何停止 hangfire 每 15 秒获取数据库?或更新间隔。

这是我正在使用的配置。

services.AddHangfire(config =>
config.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseDefaultTypeSerializer()
.UseSqlServerStorage(configuration.GetConnectionString(“BackOffice”))
);
var sqlStorage = new SqlServerStorage(configuration.GetConnectionString(“BackOffice”));
JobStorage.Current = sqlStorage;

services.AddHangfireServer(sqlStorage);
GlobalConfiguration.Configuration.UseSqlServerStorage(configuration.GetConnectionString(“BackOffice”));
services.AddHttpClient();`

如果你知道请帮助我,谢谢

【问题讨论】:

    标签: c# sql-server asp.net-core hangfire


    【解决方案1】:

    您要查找的关键字是“配置轮询间隔”。 Hangfire 轮询 SQL 服务器以查找需要执行的任何作业,默认值为 15 秒。您可以在 SqlServerStorageOptions documented here 中更改它

    摘自链接:

    var options = new SqlServerStorageOptions
    {
        SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
        QueuePollInterval = TimeSpan.Zero
    };
    
    GlobalConfiguration.Configuration.UseSqlServerStorage("<name or connection string>", options);
    

    【讨论】:

    • 我试了一下,每 15 秒检查一次数据库,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2012-04-19
    • 1970-01-01
    • 2018-10-22
    • 2011-03-17
    • 2015-12-17
    相关资源
    最近更新 更多