Skip to content

Commit

Permalink
Prevent blocking on health check in container
Browse files Browse the repository at this point in the history
  • Loading branch information
biegehydra committed Oct 22, 2023
1 parent 0c15f0b commit 2b2b381
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LibPostalApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
app.MapHealthChecks("/health");
app.Use(async (context, next) =>
{
if (context.Request.Path.StartsWithSegments("/health"))
if (LibPostalService.Initialized && context.Request.Path.StartsWithSegments("/health"))
{
var libPostal = app.Services.GetRequiredService<ILibPostalService>();
var testParse = libPostal.ParseAddress(TestData.TestAddress);
Expand Down
2 changes: 2 additions & 0 deletions LibPostalApi/Services/LibPostalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace LibPostalApi.Services;

public class LibPostalService : ILibPostalService
{
public static bool Initialized = false;
private readonly LibPostal _libPostal;
public LibPostalService(IConfiguration config)
{
Expand All @@ -21,6 +22,7 @@ public LibPostalService(IConfiguration config)
_libPostal.LoadParser();
_libPostal.LoadLanguageClassifier();
_libPostal.PrintFeatures = true;
Initialized = true;
}

public (AddressParserResponse[]? Results, int Successes, int Failures) ParseAddress(List<string> addresses, ParseOptions? dtoOptions)
Expand Down

0 comments on commit 2b2b381

Please sign in to comment.