project reorganized

This commit is contained in:
2024-04-27 22:36:16 +02:00
Unverified
parent fcca2119a5
commit 4b333878b8
233 changed files with 4916 additions and 11471 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using WatchIt.Database;
using WatchIt.Database.Model.Account;
namespace WatchIt.WebAPI.WorkerServices;
public class DeleteExpiredRefreshTokensService(ILogger<DeleteExpiredRefreshTokensService> logger, DatabaseContext database) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
Task delayTask = Task.Delay(300000, stoppingToken);
Task actionTask = Action();
await Task.WhenAll(delayTask, actionTask);
}
}
protected async Task Action()
{
IEnumerable<AccountRefreshToken> tokens = database.AccountRefreshTokens.Where(x => x.ExpirationDate < DateTime.UtcNow);
database.AccountRefreshTokens.AttachRange(tokens);
database.AccountRefreshTokens.RemoveRange(tokens);
await database.SaveChangesAsync();
}
}