@@ -2,15 +2,13 @@ package procs
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"time"
7
6
8
7
"github.com/ItsNotGoodName/smtpbridge/internal/core"
9
8
"github.com/ItsNotGoodName/smtpbridge/internal/db"
10
9
"github.com/ItsNotGoodName/smtpbridge/internal/events"
11
10
"github.com/ItsNotGoodName/smtpbridge/internal/files"
12
11
"github.com/ItsNotGoodName/smtpbridge/internal/models"
13
- "github.com/dustin/go-humanize"
14
12
"github.com/rs/zerolog/log"
15
13
)
16
14
@@ -91,30 +89,28 @@ func gardenerDeleteByAttachmentSize(cc *core.Context, policy models.RetentionPol
91
89
attachmentSize := * policy .AttachmentSize
92
90
93
91
if storage .AttachmentSize > attachmentSize {
94
- count := humanize .Bytes (uint64 (storage .AttachmentSize - attachmentSize ))
95
- log .Info ().Str ("count" , count ).Msg ("Deleting attachment files by attachment size retention policy" )
96
-
97
- err := files .DeleteFileUntilSize (cc , storage .AttachmentSize , attachmentSize )
92
+ age := policy .EnvelopeAgeDate ()
93
+ log .Info ().Time ("age" , age ).Msg ("Deleting attachment files by attachment size retention policy" )
94
+ err := files .DeleteFileUntilSize (cc , storage .AttachmentSize , attachmentSize , age )
98
95
if err != nil {
99
96
log .Err (err ).Msg ("Failed to delete attachment files by attachment size retention policy" )
100
97
}
101
98
}
102
99
}
103
100
104
101
func gardenerDeleteByEnvelopeCount (cc * core.Context , policy models.RetentionPolicy , storage models.Storage ) {
105
- fmt .Println ("---------" , policy .EnvelopeCount )
106
102
if policy .EnvelopeCount == nil {
107
103
return
108
104
}
109
105
envelopeCount := * policy .EnvelopeCount
110
106
111
107
if storage .EnvelopeCount > envelopeCount {
112
- date := time . Now (). Add ( - policy .MinEnvelopeAge )
113
- count , err := db .EnvelopeDeleteUntilCount (cc , envelopeCount , date )
108
+ age := policy .EnvelopeAgeDate ( )
109
+ count , err := db .EnvelopeDeleteUntilCount (cc , envelopeCount , age )
114
110
if err != nil {
115
- log .Err (err ).Time ("age" , date ).Int ("keep" , envelopeCount ).Msg ("Failed to envelopes by envelope count retention policy" )
111
+ log .Err (err ).Time ("age" , age ).Int ("keep" , envelopeCount ).Msg ("Failed to envelopes by envelope count retention policy" )
116
112
} else {
117
- log .Info ().Time ("age" , date ).Int ("keep" , envelopeCount ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by envelope count retention policy" )
113
+ log .Info ().Time ("age" , age ).Int ("keep" , envelopeCount ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by envelope count retention policy" )
118
114
}
119
115
}
120
116
}
@@ -123,17 +119,13 @@ func gardenerDeleteByAge(cc *core.Context, policy models.RetentionPolicy) {
123
119
if policy .EnvelopeAge == nil {
124
120
return
125
121
}
126
- envelopeAge := * policy .EnvelopeAge
127
122
128
- date := time .Now ().Add (- envelopeAge )
129
- if policy .MinEnvelopeAge > envelopeAge {
130
- date .Add (- policy .MinEnvelopeAge )
131
- }
132
- count , err := db .EnvelopeDeleteOlderThan (cc , date )
123
+ age := policy .EnvelopeAgeDate ()
124
+ count , err := db .EnvelopeDeleteOlderThan (cc , age )
133
125
if err != nil {
134
- log .Err (err ).Time ("age" , date ).Msg ("Failed to delete envelopes by age retention policy" )
126
+ log .Err (err ).Time ("age" , age ).Msg ("Failed to delete envelopes by age retention policy" )
135
127
} else {
136
- log .Info ().Time ("age" , date ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by age retention policy" )
128
+ log .Info ().Time ("age" , age ).Int64 ("deleted" , count ).Msg ("Deleted envelopes by age retention policy" )
137
129
}
138
130
}
139
131
0 commit comments