Skip to content

Commit

Permalink
Fix Hangfire DB connection config (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Jul 26, 2024
1 parent ce719db commit 1680605
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static IHostApplicationBuilder AddHangfire(this IHostApplicationBuilder b
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UsePostgreSqlStorage(o => o.UseExistingNpgsqlConnection(sp.GetRequiredService<NpgsqlDataSource>().CreateConnection())));
.UsePostgreSqlStorage(o => o.UseConnectionFactory(new DbDataSourceConnectionFactory(sp.GetRequiredService<NpgsqlDataSource>()))));
}

return builder;
Expand Down Expand Up @@ -94,4 +94,9 @@ public static string GetPostgresConnectionString(this IConfiguration configurati
// We rely on error details to get the offending duplicate key values in the TrsDataSyncHelper
IncludeErrorDetail = true
}.ConnectionString;

private class DbDataSourceConnectionFactory(NpgsqlDataSource dataSource) : IConnectionFactory
{
public NpgsqlConnection GetOrCreateConnection() => dataSource.CreateConnection();
}
}

0 comments on commit 1680605

Please sign in to comment.