c# - Hangfire 多台服务器

标签 c# .net-core hangfire

我正在构建一个 .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/

相关文章:

angular - 如何将带有 Angular 表单数据的对象列表发布到 .Net Core Web API

hangfire - 如何使用unity配置hangfire?

mongodb - 无法在 Visual Studio 2013 中引用 Hangfire.Mongo

c# - WPF 进度条在几条之后停止

c# - getter 和 setter 中的附加操作

c# - 如何将 Sprite 随机移动到控制台C#中的某个点

c# - ILogger 不返回 JSON 格式的消息和对象

.net - 如何将多个 .NET Core 程序集合并为一个(.dll/.exe)?

c# - hangfire,RecurringJob AddOrUpdate反射调用c#

c# - MVVM 共享代码 Win8 和 WP8 以及文件访问