diff --git a/back/.program_data/app.db-wal b/back/.program_data/app.db-wal index 40def1b..9157b2c 100644 Binary files a/back/.program_data/app.db-wal and b/back/.program_data/app.db-wal differ diff --git a/back/.program_data/imgs/systemkey.lock b/back/.program_data/imgs/systemkey.lock index 718fc98..92b2ff1 100644 --- a/back/.program_data/imgs/systemkey.lock +++ b/back/.program_data/imgs/systemkey.lock @@ -1,5 +1,5 @@ { "email": "sys@t.em", - "key": "c1d6bd4e-ac32-4859-b2f5-fcda1c190934", - "password": "Tx,bA%8KPn_dç8v[" + "key": "aa0e0979-99db-42e7-8b60-91c2d055b9d0", + "password": "+z1L[oYUupZ>L{4a" } \ No newline at end of file diff --git a/back/ServicesExtensions/Options.cs b/back/ServicesExtensions/Options.cs index 7ee253a..686ebd1 100644 --- a/back/ServicesExtensions/Options.cs +++ b/back/ServicesExtensions/Options.cs @@ -1,3 +1,4 @@ +using back.healthchecks.Options; using back.Options; namespace back.ServicesExtensions; @@ -14,6 +15,8 @@ public static partial class ServicesExtensions services.Configure(DatabaseConfig.BlobStorage, config.GetSection(DatabaseConfig.BlobStorage)); services.Configure(config.GetSection(nameof(MailServerOptions))); + services.Configure(HealthChecksConfigs.Sqlite, config.GetSection(HealthChecksConfigs.Sqlite)); + services.PostConfigure(databases => { if (!string.IsNullOrEmpty(databases.BaseDirectory) && !Directory.Exists(databases.BaseDirectory)) diff --git a/back/appsettings.Development.json b/back/appsettings.Development.json index 0868ace..46009f1 100644 --- a/back/appsettings.Development.json +++ b/back/appsettings.Development.json @@ -17,5 +17,13 @@ "Usuario": "", "Password": "", "EnableSsl": true + }, + "HealthChecksConfigs": { + "Sqlite": { + "RetryAttempts" : 2, + "Timeout" : "00:05:00", + "RetryDelay" : "00:00:10", + "Severity": "Info" + } } } diff --git a/back/healthchecks/options/HealthChecksConfigs.cs b/back/healthchecks/options/HealthChecksConfigs.cs new file mode 100644 index 0000000..2c432ac --- /dev/null +++ b/back/healthchecks/options/HealthChecksConfigs.cs @@ -0,0 +1,8 @@ +using HealthChecksConfigsBase = healthchecks.Options.HealthChecksConfigs; + +namespace back.healthchecks.Options; + +public partial class HealthChecksConfigs : HealthChecksConfigsBase +{ + public const string Sqlite = "Sqlite"; +} diff --git a/back/healthchecks/sqlite.cs b/back/healthchecks/sqlite.cs index e7727a9..5f22ce3 100644 --- a/back/healthchecks/sqlite.cs +++ b/back/healthchecks/sqlite.cs @@ -1,27 +1,29 @@ using back.Options; using healthchecks; +using healthchecks.Abstracts; +using back.healthchecks.Options; using Microsoft.Extensions.Options; namespace back.healthchecks; -[HealthCheckExecutionOptions(retryAttempts: 2, timeout: "00:00:05", retryDelay: "00:00:01", severity: HealthCheckSeverity.Critical)] -public class SqliteHealthCheck : IHealthCheck +public class SqliteHealthCheck(IOptionsMonitor databaseConfig, IOptionsMonitor healthchecksConfig) : IHealthCheck { - private readonly DatabaseConfig config; - public SqliteHealthCheck(IOptionsMonitor optionsSnapshot) - { - config = optionsSnapshot.Get(DatabaseConfig.DataStorage); - } + private readonly DatabaseConfig databaseConfig = databaseConfig.Get(DatabaseConfig.DataStorage); + private readonly HealthChecksConfigs hcConfig = healthchecksConfig.Get(HealthChecksConfigs.Sqlite); + + public string Description => "Conecta con la base de datos SQLite y trata de hacer una consulta sobre la tabla Users."; + public int? RetryAttempts => hcConfig.RetryAttempts ?? 2; + public TimeSpan? Timeout => hcConfig.Timeout ?? TimeSpan.FromSeconds(5); + public TimeSpan? RetryDelay => hcConfig.RetryDelay ?? TimeSpan.FromSeconds(1); + public HealthCheckSeverity? Severity => hcConfig.Severity ?? HealthCheckSeverity.Critical; public Task CheckAsync(CancellationToken cancellationToken = default) { - // check if can connect to sqlite database - // then run a query to Users table to see if User.SystemUser exists var isHealthy = false; var details = string.Empty; try { - using var connection = new Microsoft.Data.Sqlite.SqliteConnection(config.ConnectionString); + using var connection = new Microsoft.Data.Sqlite.SqliteConnection(databaseConfig.ConnectionString); connection.Open(); using var command = connection.CreateCommand(); command.CommandText = $"SELECT COUNT(1) FROM Users WHERE Id = '{DataModels.User.SystemUserId}';"; diff --git a/back/services/bussines/PhotoService/IPhotoService.cs b/back/services/bussines/PhotoService/IPhotoService.cs index 80c24f9..8d045bb 100644 --- a/back/services/bussines/PhotoService/IPhotoService.cs +++ b/back/services/bussines/PhotoService/IPhotoService.cs @@ -1,6 +1,5 @@ using back.DataModels; using back.DTO; -using DependencyInjector.Abstractions.ClassTypes; using DependencyInjector.Lifetimes; namespace back.services.bussines.PhotoService; diff --git a/back/services/bussines/UserService/IUserService.cs b/back/services/bussines/UserService/IUserService.cs index 76dc8e3..ec9bc48 100644 --- a/back/services/bussines/UserService/IUserService.cs +++ b/back/services/bussines/UserService/IUserService.cs @@ -1,5 +1,4 @@ using back.DataModels; -using DependencyInjector.Abstractions.ClassTypes; using DependencyInjector.Lifetimes; namespace back.services.bussines.UserService;