Portfolio.Web 1.0.0.0
.NET, Blazor, WPF와 서비스 운영 경험을 프로젝트·이력·기술 스택 단위로 보여주는 개발자 포트폴리오입니다.
로딩중...
검색중...
일치하는것 없음
GhostAccountCleanupService.cs
이 파일의 문서화 페이지로 가기
1using Microsoft.Extensions.Hosting;
2using Microsoft.Extensions.Logging;
3
5
14public class GhostAccountCleanupService : BackgroundService
15{
33 private readonly IProjectStore _projects;
42 private readonly ILogger<GhostAccountCleanupService> _log;
43
78 IProjectStore projects,
79 ILogger<GhostAccountCleanupService> log)
80 {
81 _tenants = tenants;
82 _projects = projects;
83 _log = log;
84 }
85
110 protected override async Task ExecuteAsync(CancellationToken ct)
111 {
112 while (!ct.IsCancellationRequested)
113 {
114 await Task.Delay(TimeSpan.FromHours(1), ct);
115 try { await CleanupAsync(); } catch (Exception ex) { _log.LogError(ex, "Cleanup error"); }
116 }
117 }
118
135 private async Task CleanupAsync()
136 {
137 var all = await _tenants.GetAllAsync();
138 var cutoff = DateTime.Now.AddHours(-24);
139 foreach (var cfg in all)
140 {
141 if (cfg.CreatedAt > cutoff) continue;
142 var projects = await _projects.GetAllAsync(cfg.Slug);
143 if (projects.Count == 0)
144 {
145 await _tenants.DeleteAsync(cfg.Slug);
146 _log.LogInformation("Ghost account deleted: {Slug}", cfg.Slug);
147 }
148 }
149 }
150}
override async Task ExecuteAsync(CancellationToken ct)
readonly ILogger< GhostAccountCleanupService > _log
GhostAccountCleanupService(IPortfolioTenantStore tenants, IProjectStore projects, ILogger< GhostAccountCleanupService > log)