Skip to content

Commit efe8c8b

Browse files
committed
Refactor health checks and error handling
- Updated error handling to catch a general `Exception`. - Adjusted health check mappings in `Program.cs`, swapping predicates for "/healthz/ready" and "/healthz/live" endpoints, affecting readiness and liveliness reporting.
1 parent cd78231 commit efe8c8b

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/PdfSmith/BackgroundServices/InstallPlaywrightBackgroundService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
using Microsoft.Playwright;
2-
using PdfSmith.HealthChecks;
1+
using PdfSmith.HealthChecks;
32

43
namespace PdfSmith.BackgroundServices;
54

65
public class InstallPlaywrightBackgroundService(PlaywrightHealthCheck playwrightHealthCheck, ILogger<InstallPlaywrightBackgroundService> logger) : BackgroundService
76
{
87
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
98
{
10-
// On Windows, it is installed in %USERPROFILE%\AppData\Local\ms-playwright by default
11-
// We can use PLAYWRIGHT_BROWSERS_PATH environment variable to change the default location
9+
// On Windows, it is installed in %USERPROFILE%\AppData\Local\ms-playwright by default.
10+
// We can use PLAYWRIGHT_BROWSERS_PATH environment variable to change the default location.
1211
var returnCode = await Task.Run(() =>
1312
{
1413
try
1514
{
1615
return Microsoft.Playwright.Program.Main(["install", "chromium"]);
1716
}
18-
catch (PlaywrightException ex)
17+
catch (Exception ex)
1918
{
2019
logger.LogError(ex, "Error while installing Chromium");
2120
return -1;

src/PdfSmith/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@
171171
app.UseRateLimiter();
172172
app.UseRequestTimeouts();
173173

174-
app.MapHealthChecks("/healthz/ready", new HealthCheckOptions
174+
app.MapHealthChecks("/healthz/live", new HealthCheckOptions
175175
{
176-
Predicate = healthCheck => healthCheck.Tags.Contains("ready"),
176+
Predicate = _ => false,
177177
ResponseWriter = HealthChecksResponseWriter()
178178
});
179179

180-
app.MapHealthChecks("/healthz/live", new HealthCheckOptions
180+
app.MapHealthChecks("/healthz/ready", new HealthCheckOptions
181181
{
182-
Predicate = _ => false,
182+
Predicate = healthCheck => healthCheck.Tags.Contains("ready"),
183183
ResponseWriter = HealthChecksResponseWriter()
184184
});
185185

0 commit comments

Comments
 (0)