hermes-server/Services/DatabaseService.cs

37 lines
1.2 KiB
C#
Raw Normal View History

2024-10-17 17:17:09 -04:00
using HermesSocketServer.Store;
namespace HermesSocketServer.Services
{
public class DatabaseService : BackgroundService
{
private readonly VoiceStore _voices;
private readonly ChatterStore _chatters;
private readonly ServerConfiguration _configuration;
2024-10-17 17:17:09 -04:00
private readonly Serilog.ILogger _logger;
public DatabaseService(VoiceStore voices, ChatterStore chatters, ServerConfiguration configuration, Serilog.ILogger logger) {
2024-10-17 17:17:09 -04:00
_voices = voices;
_chatters = chatters;
_configuration = configuration;
2024-10-17 17:17:09 -04:00
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
_logger.Information("Loading TTS voices...");
await _voices.Load();
_logger.Information("Loading TTS chatters' voice.");
await _chatters.Load();
2024-10-17 17:17:09 -04:00
await Task.Run(async () =>
{
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(_configuration.Database.SaveDelayInSeconds));
2024-10-17 17:17:09 -04:00
await _voices.Save();
await _chatters.Save();
2024-10-17 17:17:09 -04:00
}
});
}
}
}