WeddingPlatform.Web 1.0.0.0
지도, 갤러리, 방명록, 계좌 안내와 배경음악을 링크 하나에 담는 무료 모바일 청첩장 서비스입니다.
로딩중...
검색중...
일치하는것 없음
GhostAccountCleanupService.cs
이 파일의 문서화 페이지로 가기
1using Microsoft.Extensions.Hosting;
2using Microsoft.Extensions.Logging;
3
5
14public sealed class GhostAccountCleanupService : BackgroundService
15{
24 private readonly ITenantStore _tenants;
33 private readonly ILogger<GhostAccountCleanupService> _logger;
42 private static readonly TimeSpan Interval = TimeSpan.FromHours(1);
51 private static readonly TimeSpan GracePeriod = TimeSpan.FromHours(24);
52
77 public GhostAccountCleanupService(ITenantStore tenants, ILogger<GhostAccountCleanupService> logger)
78 {
79 _tenants = tenants;
80 _logger = logger;
81 }
82
107 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
108 {
109 while (!stoppingToken.IsCancellationRequested)
110 {
111 await Task.Delay(Interval, stoppingToken).ConfigureAwait(false);
112 await RunCleanupAsync(stoppingToken).ConfigureAwait(false);
113 }
114 }
115
140 private async Task RunCleanupAsync(CancellationToken ct)
141 {
142 try
143 {
144 var all = await _tenants.GetAllAsync(ct).ConfigureAwait(false);
145 var cutoff = DateTime.Now - GracePeriod;
146
147 foreach (var t in all)
148 {
149 if (t.GalleryFileNames.Count > 0) continue;
150 if (t.CreatedAt > cutoff) continue;
151
152 await _tenants.DeleteAsync(t.Slug, ct).ConfigureAwait(false);
153 _logger.LogInformation("고스트 계정 자동 삭제: {Slug} (생성: {CreatedAt:g}, 사진 0장)", t.Slug, t.CreatedAt);
154 }
155 }
156 catch (Exception ex) when (ex is not OperationCanceledException)
157 {
158 _logger.LogError(ex, "고스트 계정 정리 중 오류 발생");
159 }
160 }
161}
readonly ILogger< GhostAccountCleanupService > _logger
GhostAccountCleanupService(ITenantStore tenants, ILogger< GhostAccountCleanupService > logger)
override async Task ExecuteAsync(CancellationToken stoppingToken)