Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Server/Components/Pages/GamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@
return;
}

var user = await UsersRepository.GetUserAsync(username.Value!);
var user = await UsersRepository.GetUserAsync(username.Value);
if (user is null)
{
user = new User { Username = username.Value! };
await UsersRepository.AddUserAsync(user);
user = new User { Username = username.Value, CreatedAt =DateTime.UtcNow};
user = await UsersRepository.AddUserAsync(user);
}

_user = user;
Expand Down
7 changes: 4 additions & 3 deletions Server/Fracture.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
<_ContentIncludedByDefault Remove="wwwroot\css\items.css" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
<PackageReference Include="Markov" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
<PackageReference Include="Microsoft.FeatureManagement" Version="4.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageReference Include="OpenAI-DotNet" Version="8.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.0" />
Expand Down
133 changes: 0 additions & 133 deletions Server/Migrations/Initial.Designer.cs

This file was deleted.

98 changes: 0 additions & 98 deletions Server/Migrations/Initial.cs

This file was deleted.

68 changes: 68 additions & 0 deletions Server/Modules/Database/DockerHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Docker.DotNet;
using Docker.DotNet.Models;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Fracture.Server.Modules.Database;

public class DockerHealthCheck : IHealthCheck
{
private readonly DockerClient _dockerClient;

public DockerHealthCheck(DockerClient dockerClient)
{
_dockerClient = dockerClient;
}

public async Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = default
)
{
try
{
var containers = await _dockerClient.Containers.ListContainersAsync(
new ContainersListParameters()
{
All = true,
Filters = new Dictionary<string, IDictionary<string, bool>>
{
{
"name",
new Dictionary<string, bool> { { "fracturePostgres", true } }
},
},
},
cancellationToken
);

var container = containers.FirstOrDefault();
if (container == null)
{
return HealthCheckResult.Unhealthy("PostgreSQL container not found");
}

var containerInfo = await _dockerClient.Containers.InspectContainerAsync(
container.ID,
cancellationToken
);

return containerInfo.State.Health?.Status switch
{
"healthy" => HealthCheckResult.Healthy(),
"starting" => HealthCheckResult.Degraded("PostgreSQL container is starting"),
"unhealthy" => HealthCheckResult.Unhealthy("PostgreSQL container is unhealthy"),
null when containerInfo.State.Running => HealthCheckResult.Healthy(
"PostgreSQL container is running, no healthcheck"
),
null => HealthCheckResult.Unhealthy("PostgreSQL container is not running"),
_ => HealthCheckResult.Unhealthy(
$"Unknown status: {containerInfo.State.Health?.Status}"
),
};
}
catch (Exception e)
{
return HealthCheckResult.Unhealthy("Failed to check Docker container", e);
}
}
}
Loading
Loading