It would be really convenient to add an overload to HangfireServiceCollectionExtensions.AddHangfireServer to allow configuration of BackgroundJobServerOptions like AddHangfire and GlobalConfiguration
Current Solution:
services.AddSingleton(provider => new BackgroundJobServerOptions
{
Queues = new[] { "default", "misc" },
WorkerCount = 1,
});
services.AddHangfireServer();
Proposed Solution:
services.AddHangfireServer(options =>
{
options.WorkCount = 1;
options.Queues = new[] {"default", "misc"};
});
I had the same issue and wondered why there was no overload too. Would be a nice addition!
According to the docs it is an option. But it is done in the Configure method and not ConfigureServices in the Startup file of core. However using this approach is not desribed in Getting Started. I do not know what difference, if any, it makes but it might be worth a try.
@djesmond In Hangfire 1.7 the AddHangfireServer was introduced to add a IHostedService to WebHost and GenericHost of ASP.NET Core 2.1+.
I believe UseHangfireServer was built around using WebHost IApplicationLifeTime for starting and stopping. Not as clean imho
I see. So AddHangfireServer can be considered the replacement for UseHangfireServer?
Indeed much simpler, thanks. Just added an overload that will be available in upcoming 1.7.5.
Most helpful comment
Indeed much simpler, thanks. Just added an overload that will be available in upcoming 1.7.5.