Skip to content

Commit

Permalink
Merge pull request #65 from by-pinja/feat/hangfire-options
Browse files Browse the repository at this point in the history
Hangfire worker count configuration
  • Loading branch information
vekuna authored Apr 23, 2021
2 parents 18574b9 + 19ddf0e commit b5ac3e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,19 @@ public void Configure(IApplicationBuilder app)

});

var workerCount = 4;
if (!string.IsNullOrEmpty(Configuration["Hangfire:WorkerCount"]))
{
if (!int.TryParse(Configuration["Hangfire:WorkerCount"], out workerCount))
{
throw new InvalidOperationException("Invalid WorkerCount on cofiguration.");
}
}

var options = new BackgroundJobServerOptions
{
Queues = HangfireConstants.GetQueues().ToArray(),
WorkerCount = 4,
WorkerCount = workerCount,
};

app.Map("/hangfire", appBuilder =>
Expand Down
5 changes: 4 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
"Hangfire": {
"AllowedIpAddresses": [],
"DashboardUser": "",
"DashboardPassword": ""
"DashboardPassword": "",
// If database connections get timeouted due to no pools available.
// It may be because of too many workers use many connections, you can reduce the amount of workers here.
"WorkerCount": 4
},
"ApplicationInsights": {
"InstrumentationKey": ""
Expand Down

0 comments on commit b5ac3e1

Please sign in to comment.