@@ -73,41 +73,54 @@ func gardener(cc *core.Context, policy models.RetentionPolicy, envCreatedC <-cha
73
73
}
74
74
}
75
75
func gardenerDeleteByAttachmentSize (cc * core.Context , policy models.RetentionPolicy , storage models.Storage ) {
76
- if policy .AttachmentSize != 0 && storage .AttachmentSize > policy .AttachmentSize {
77
- count := humanize .Bytes (uint64 (storage .AttachmentSize - policy .AttachmentSize ))
76
+ if policy .AttachmentSize == nil {
77
+ return
78
+ }
79
+ attachmentSize := * policy .AttachmentSize
80
+
81
+ if storage .AttachmentSize > attachmentSize {
82
+ count := humanize .Bytes (uint64 (storage .AttachmentSize - attachmentSize ))
78
83
log .Info ().Str ("count" , count ).Msg ("Deleting attachment files by attachment size retention policy" )
79
84
80
- err := files .DeleteFileUntilSize (cc , storage .AttachmentSize , policy . AttachmentSize )
85
+ err := files .DeleteFileUntilSize (cc , storage .AttachmentSize , attachmentSize )
81
86
if err != nil {
82
87
log .Err (err ).Msg ("Failed to delete attachment files by attachment size retention policy" )
83
88
}
84
89
}
85
90
}
86
91
87
92
func gardenerDeleteByEnvelopeCount (cc * core.Context , policy models.RetentionPolicy , storage models.Storage ) {
88
- if policy .EnvelopeCount != 0 && storage .EnvelopeCount > policy .EnvelopeCount {
93
+ if policy .EnvelopeCount == nil {
94
+ return
95
+ }
96
+ envelopeCount := * policy .EnvelopeCount
97
+
98
+ if storage .EnvelopeCount > envelopeCount {
89
99
date := time .Now ().Add (- policy .MinEnvelopeAge )
90
- count , err := db .EnvelopeDeleteUntilCount (cc , policy . EnvelopeCount , date )
100
+ count , err := db .EnvelopeDeleteUntilCount (cc , envelopeCount , date )
91
101
if err != nil {
92
- log .Err (err ).Time ("age" , date ).Int ("keep" , policy . EnvelopeCount ).Msg ("Failed to envelopes by envelope count retention policy" )
102
+ log .Err (err ).Time ("age" , date ).Int ("keep" , envelopeCount ).Msg ("Failed to envelopes by envelope count retention policy" )
93
103
} else {
94
- log .Info ().Time ("age" , date ).Int ("keep" , policy . EnvelopeCount ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by envelope count retention policy" )
104
+ log .Info ().Time ("age" , date ).Int ("keep" , envelopeCount ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by envelope count retention policy" )
95
105
}
96
106
}
97
107
}
98
108
99
109
func gardenerDeleteByAge (cc * core.Context , policy models.RetentionPolicy ) {
100
- if policy .EnvelopeAge != 0 {
101
- date := time .Now ().Add (- policy .EnvelopeAge )
102
- if policy .MinEnvelopeAge > policy .EnvelopeAge {
103
- date .Add (- policy .MinEnvelopeAge )
104
- }
105
- count , err := db .EnvelopeDeleteOlderThan (cc , date )
106
- if err != nil {
107
- log .Err (err ).Time ("age" , date ).Msg ("Failed to delete envelopes by age retention policy" )
108
- } else {
109
- log .Info ().Time ("age" , date ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by age retention policy" )
110
- }
110
+ if policy .EnvelopeAge == nil {
111
+ return
112
+ }
113
+ envelopeAge := * policy .EnvelopeAge
114
+
115
+ date := time .Now ().Add (- envelopeAge )
116
+ if policy .MinEnvelopeAge > envelopeAge {
117
+ date .Add (- policy .MinEnvelopeAge )
118
+ }
119
+ count , err := db .EnvelopeDeleteOlderThan (cc , date )
120
+ if err != nil {
121
+ log .Err (err ).Time ("age" , date ).Msg ("Failed to delete envelopes by age retention policy" )
122
+ } else {
123
+ log .Info ().Time ("age" , date ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by age retention policy" )
111
124
}
112
125
}
113
126
0 commit comments