- Add 4 PG entities: VerificationCode, RateLimitEntry, TokenBlacklistEntry, CacheEntry - Add 4 services: VerificationService, RateLimitService, TokenBlacklistService, CacheService - Add CleanupBackgroundService for periodic expired data cleanup - Add MigrationHelper for safe schema migration without data loss - Update AuthController: real SMS code generation, rate limiting, logout endpoint with JWT blacklist - Update JwtProvider: add JTI claim for token revocation - Update Program.cs: register new services, JWT blacklist validation, DB migration - Remove StackExchange.Redis NuGet package and all Redis config references - Update start-dev.bat: 6→5 services, remove Redis startup - Update docs: remove Redis references from all documentation - Fix: logout button spacing on profile page - Fix: .gitignore data/→/data/ to not ignore Infrastructure/Data/
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using HealthManager.Application.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace HealthManager.WebApi.Services;
|
|
|
|
public class CleanupBackgroundService(
|
|
IServiceScopeFactory scopeFactory) : BackgroundService
|
|
{
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
using var scope = scopeFactory.CreateScope();
|
|
var verification = scope.ServiceProvider.GetRequiredService<VerificationService>();
|
|
var tokenBlacklist = scope.ServiceProvider.GetRequiredService<TokenBlacklistService>();
|
|
|
|
await verification.CleanupExpiredAsync();
|
|
await tokenBlacklist.CleanupExpiredAsync();
|
|
|
|
var db = scope.ServiceProvider.GetRequiredService<Infrastructure.Data.AppDbContext>();
|
|
await db.RateLimitEntries.Where(r => r.ExpiresAt < DateTime.UtcNow).ExecuteDeleteAsync(stoppingToken);
|
|
await db.CacheEntries.Where(c => c.ExpiresAt < DateTime.UtcNow).ExecuteDeleteAsync(stoppingToken);
|
|
}
|
|
catch { /* skip cleanup errors */ }
|
|
|
|
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
|
}
|
|
}
|
|
}
|