Portfolio.Web
1.0.0.0
.NET, Blazor, WPF와 서비스 운영 경험을 프로젝트·이력·기술 스택 단위로 보여주는 개발자 포트폴리오입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
GhostAccountCleanupService.cs
이 파일의 문서화 페이지로 가기
1
using
Microsoft.Extensions.Hosting;
2
using
Microsoft.Extensions.Logging;
3
4
namespace
PortfolioApp.Services
;
5
14
public
class
GhostAccountCleanupService
: BackgroundService
15
{
24
private
readonly
IPortfolioTenantStore
_tenants
;
33
private
readonly
IProjectStore
_projects
;
42
private
readonly ILogger<GhostAccountCleanupService>
_log
;
43
76
public
GhostAccountCleanupService
(
77
IPortfolioTenantStore
tenants,
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
}
PortfolioApp.Services
Definition
GhostAccountCleanupService.cs:4
PortfolioApp.Services.GhostAccountCleanupService.CleanupAsync
async Task CleanupAsync()
Definition
GhostAccountCleanupService.cs:135
PortfolioApp.Services.GhostAccountCleanupService._projects
readonly IProjectStore _projects
Definition
GhostAccountCleanupService.cs:33
PortfolioApp.Services.GhostAccountCleanupService._tenants
readonly IPortfolioTenantStore _tenants
Definition
GhostAccountCleanupService.cs:24
PortfolioApp.Services.GhostAccountCleanupService.ExecuteAsync
override async Task ExecuteAsync(CancellationToken ct)
Definition
GhostAccountCleanupService.cs:110
PortfolioApp.Services.GhostAccountCleanupService._log
readonly ILogger< GhostAccountCleanupService > _log
Definition
GhostAccountCleanupService.cs:42
PortfolioApp.Services.GhostAccountCleanupService.GhostAccountCleanupService
GhostAccountCleanupService(IPortfolioTenantStore tenants, IProjectStore projects, ILogger< GhostAccountCleanupService > log)
Definition
GhostAccountCleanupService.cs:76
PortfolioApp.Services.IPortfolioTenantStore
Definition
IPortfolioTenantStore.cs:14
PortfolioApp.Services.IProjectStore
Definition
IProjectStore.cs:14
Services
GhostAccountCleanupService.cs
다음에 의해 생성됨 :
1.17.0