我有一个在 Azure 上运行的 Web Api 应用程序。我每天早上 2:00 运行一个调度程序作业,这会创建大量的hangfire 作业。
目前,Web Api 应用只有一个可用实例,该实例配置为根据 CPU 指标进行横向扩展。这些正在运行的hangfire作业将CPU百分比增加到极限,并创建api应用程序的新的可用实例。
不幸的是,在我看来,给定的hangfire作业在创建它的实例上运行。如何配置 Hangfire 在所有可用实例上分派(dispatch)作业?
最佳答案
Unfortunately, it seems to me a given hangfire job runs on the instance that created it. How can I configure Hangfire to dispatch jobs on all the available instances ?
据我所知,默认情况下该作业将位于default
队列中。如果您运行多个服务器实例,作业将分发到可用实例。为了进行测试,我只是添加我的任务,如下所示:
Enumerable.Range(11, 30).ForEach(i =>
{
BackgroundJob.Enqueue(() => Console.WriteLine($"[Task-{i}] Getting Started with HangFire!"));
});
然后,在控制台应用程序中处理作业,如下所示:
using (var server = new BackgroundJobServer())
{
Console.WriteLine("Hangfire Server started. Press any key to exit...");
Console.ReadKey();
}
我启动了两个服务器实例,得到了以下结果:
关于c# - 如何在所有 Azure 可用实例上分派(dispatch) Hangfire 作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47595352/