fix: player/tribe snapshot - clean up data only when Special = false
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Dawid Wysokiński 2022-12-28 11:25:23 +01:00
parent 75d909ac6e
commit 1caad44e51
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
5 changed files with 23 additions and 3 deletions

View File

@ -40,4 +40,8 @@ create-job-update-ennoblements:
.PHONY: create-job-create-snapshots
create-job-create-snapshots:
kubectl create job --from=cronjob/twhelp-job-create-snapshots-dev twhelp-job-create-snapshots
kubectl create job --from=cronjob/twhelp-job-create-snapshots-dev twhelp-job-create-snapshots
.PHONY: create-job-clean-up
create-job-clean-up:
kubectl create job --from=cronjob/twhelp-job-clean-up-dev twhelp-job-clean-up

View File

@ -81,7 +81,7 @@ func (p *PlayerSnapshot) Create(ctx context.Context, key string, date time.Time)
}
func (p *PlayerSnapshot) CleanUp(ctx context.Context, srv domain.Server) error {
if srv.Open || srv.PlayerSnapshotsCreatedAt.After(time.Now().Add(-30*24*time.Hour) /* 30 days */) {
if srv.Special || srv.Open || srv.PlayerSnapshotsCreatedAt.After(time.Now().Add(-30*24*time.Hour) /* 30 days */) {
return nil
}

View File

@ -93,6 +93,14 @@ func TestPlayerSnapshot_CleanUp(t *testing.T) {
svc := service.NewPlayerSnapshot(repo, playerSvc)
assert.NoError(t, svc.CleanUp(context.Background(), domain.Server{
Key: serverKey,
Special: true,
Open: false,
TribeSnapshotsCreatedAt: time.Now().Add(-30 * 24 * time.Hour),
}))
assert.Equal(t, 0, repo.DeleteCallCount()) // only servers with Special = false
assert.NoError(t, svc.CleanUp(context.Background(), domain.Server{
Key: serverKey,
Open: true,

View File

@ -83,7 +83,7 @@ func (t *TribeSnapshot) Create(ctx context.Context, key string, date time.Time)
}
func (t *TribeSnapshot) CleanUp(ctx context.Context, srv domain.Server) error {
if srv.Open || srv.TribeSnapshotsCreatedAt.After(time.Now().Add(-30*24*time.Hour) /* 30 days */) {
if srv.Special || srv.Open || srv.TribeSnapshotsCreatedAt.After(time.Now().Add(-30*24*time.Hour) /* 30 days */) {
return nil
}

View File

@ -102,6 +102,14 @@ func TestTribeSnapshot_CleanUp(t *testing.T) {
svc := service.NewTribeSnapshot(repo, tribeSvc)
assert.NoError(t, svc.CleanUp(context.Background(), domain.Server{
Key: serverKey,
Special: true,
Open: false,
TribeSnapshotsCreatedAt: time.Now().Add(-30 * 24 * time.Hour),
}))
assert.Equal(t, 0, repo.DeleteCallCount()) // only servers with Special = false
assert.NoError(t, svc.CleanUp(context.Background(), domain.Server{
Key: serverKey,
Open: true,