Added channel saving. Fixed channel loading. Added policy store to channels.

This commit is contained in:
Tom
2024-10-20 19:32:30 +00:00
parent 5d69c647cf
commit a9cdb65895
6 changed files with 178 additions and 16 deletions

View File

@ -4,13 +4,15 @@ namespace HermesSocketServer.Services
{
public class DatabaseService : BackgroundService
{
private readonly ChannelManager _channels;
private readonly VoiceStore _voices;
private readonly UserStore _users;
private readonly ServerConfiguration _configuration;
private readonly Serilog.ILogger _logger;
public DatabaseService(VoiceStore voices, UserStore users, ServerConfiguration configuration, Serilog.ILogger logger)
public DatabaseService(ChannelManager channels, VoiceStore voices, UserStore users, ServerConfiguration configuration, Serilog.ILogger logger)
{
_channels = channels;
_voices = voices;
_users = users;
_configuration = configuration;
@ -26,14 +28,16 @@ namespace HermesSocketServer.Services
await Task.Run(async () =>
{
var tasks = new List<Task>();
await Task.Delay(TimeSpan.FromSeconds(_configuration.Database.SaveDelayInSeconds));
while (true)
{
tasks.Add(_voices.Save());
tasks.Add(_users.Save());
tasks.Add(Task.Delay(TimeSpan.FromSeconds(_configuration.Database.SaveDelayInSeconds)));
await Task.WhenAll(tasks);
await Task.WhenAll([
_voices.Save(),
_users.Save(),
_channels.Save(),
Task.Delay(TimeSpan.FromSeconds(_configuration.Database.SaveDelayInSeconds)),
]);
}
});
}