fix: player/tribe snapshot - clean up data only when Special = false
This commit is contained in:
parent
75d909ac6e
commit
1caad44e51
6
Makefile
6
Makefile
|
@ -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
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Reference in New Issue
Block a user