-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added migration projects and wait processes at startup
- Loading branch information
1 parent
4ce41e5
commit c4c38bb
Showing
12 changed files
with
453 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using Aspire.Hosting.ApplicationModel; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
/// <summary> | ||
/// An annotation that associates a health check factory with a resource | ||
/// </summary> | ||
/// <param name="healthCheckFactory">A function that creates the health check</param> | ||
public class HealthCheckAnnotation(Func<IResource, CancellationToken, Task<IHealthCheck?>> healthCheckFactory) : IResourceAnnotation | ||
{ | ||
public Func<IResource, CancellationToken, Task<IHealthCheck?>> HealthCheckFactory { get; } = healthCheckFactory; | ||
|
||
public static HealthCheckAnnotation Create(Func<string, IHealthCheck> connectionStringFactory) | ||
{ | ||
return new(async (resource, token) => | ||
{ | ||
if (resource is not IResourceWithConnectionString c) | ||
{ | ||
return null; | ||
} | ||
|
||
if (await c.GetConnectionStringAsync(token) is not string cs) | ||
{ | ||
return null; | ||
} | ||
|
||
return connectionStringFactory(cs); | ||
}); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/TagzApp.AppHostExtensions/PostgreSqlHealthCheckExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
using HealthChecks.NpgSql; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
public static class PostgreSqlHealthCheckExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a health check to the PostgreSQL server resource. | ||
/// </summary> | ||
public static IResourceBuilder<PostgresServerResource> WithHealthCheck(this IResourceBuilder<PostgresServerResource> builder) | ||
{ | ||
return builder.WithAnnotation(HealthCheckAnnotation.Create(cs => new NpgSqlHealthCheck(new NpgSqlHealthCheckOptions(cs)))); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a health check to the PostgreSQL database resource. | ||
/// </summary> | ||
public static IResourceBuilder<PostgresDatabaseResource> WithHealthCheck(this IResourceBuilder<PostgresDatabaseResource> builder) | ||
{ | ||
return builder.WithAnnotation(HealthCheckAnnotation.Create(cs => new NpgSqlHealthCheck(new NpgSqlHealthCheckOptions(cs)))); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/TagzApp.AppHostExtensions/RedisResourceHealthCheckExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
using HealthChecks.Redis; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
public static class RedisResourceHealthCheckExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a health check to the Redis server resource. | ||
/// </summary> | ||
public static IResourceBuilder<RedisResource> WithHealthCheck(this IResourceBuilder<RedisResource> builder) | ||
{ | ||
return builder.WithAnnotation(HealthCheckAnnotation.Create(cs => new RedisHealthCheck(cs))); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/TagzApp.AppHostExtensions/TagzApp.AppHostExtensions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting" Version="8.0.*" /> | ||
<PackageReference Include="Aspire.Hosting.Redis" Version="8.0.*" /> | ||
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="8.0.*" /> | ||
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.1" /> | ||
<PackageReference Include="AspNetCore.HealthChecks.Redis" Version="8.0.1" /> | ||
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.