gpt4 book ai didi

c# - Hangfire 多台服务器

转载 作者:行者123 更新时间:2023-12-03 23:55:35 25 4
gpt4 key购买 nike

我正在构建一个 .net 核心 Web 应用程序,在服务器端,我正在为计划任务和长期任务添加 hangfire。在 Startup.cs 文件中,我添加了:

services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")));

在配置功能中我添加了这个:
app.UseHangfireServer();
app.UseHangfireDashboard();

现在的问题是,每当我运行应用程序时,仪表板中都会显示一个新的服务器实例。
enter image description here

有没有办法确保只有一台服务器在运行?或者如果我可以在停止应用程序 (IIS) 时关闭服务器并在运行应用程序时重新启动它

最佳答案

这似乎解决了一些问题。它应该清除所有在过去 15 秒内未处于事件状态的服务器。我目前有这是我的应用程序startup.cs。感觉不是正确的解决方案,但受他们提供的限制。

        // Clean up Servers List
Hangfire.Storage.IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
JobStorage.Current.GetConnection().RemoveTimedOutServers(new TimeSpan(0, 0, 15));

app.UseHangfireServer(new BackgroundJobServerOptions
{
WorkerCount = 1,
Queues = new[] { "jobqueue" },
ServerName = "HangfireJobServer",
});

RecurringJob.AddOrUpdate("ProcessJob", () => YourMethod(), AppSettings.JobCron, TimeZoneInfo.Local, "jobqueue");

关于c# - Hangfire 多台服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48771152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com