Skip to content

Commit

Permalink
Added health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaffitsancsoft committed Apr 10, 2024
1 parent b02ebd2 commit c8ea612
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Text;

namespace HQ.Server;
namespace HQ.Server.API;

// https://github.com/dotnet/aspnet-api-versioning/blob/main/examples/AspNetCore/WebApi/OpenApiExample/ConfigureSwaggerOptions.cs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace HQ.Server.Controllers;
namespace HQ.Server.API.Controllers;

[Authorize]
[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Text.Json;

namespace HQ.Server;
namespace HQ.Server.API;

// https://github.com/dotnet/aspnet-api-versioning/blob/main/examples/AspNetCore/WebApi/OpenApiExample/SwaggerDefaultValues.cs

Expand Down
13 changes: 12 additions & 1 deletion src/dotnet/HQ.Server/Commands/APICommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using HQ.Server.API;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Spectre.Console.Cli;
Expand All @@ -14,6 +16,8 @@ public override Task<int> ExecuteAsync(CommandContext context)
var args = context.Remaining.Raw.ToArray();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHealthChecks();

// Add services to the container.
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
builder.Services.AddSwaggerGen(c =>
Expand Down Expand Up @@ -67,6 +71,13 @@ public override Task<int> ExecuteAsync(CommandContext context)
var app = builder.Build();

// Configure the HTTP request pipeline.

// Run all health checks
app.MapHealthChecks("/health/startup");

// Only run simple health check testing to see if server responds
app.MapHealthChecks("/healthz", new HealthCheckOptions { Predicate = _ => false });

app.UseSwagger();
app.UseSwaggerUI(c =>
{
Expand Down
1 change: 0 additions & 1 deletion src/dotnet/HQ.Server/Commands/WorkerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public override Task<int> ExecuteAsync(CommandContext context)
{
var args = context.Remaining.Raw.ToArray();
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
Expand Down
24 changes: 0 additions & 24 deletions src/dotnet/HQ.Server/Worker.cs

This file was deleted.

0 comments on commit c8ea612

Please sign in to comment.