mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-21 11:37:07 +00:00
Logging and unit test changes
Logging methods were renamed so they don't trigger go-vet warnings for error() and Error() formatting. Unit tests were updated to use new github.com/stretchr repo (was renamed from stretchrcom) Missing methods were added to Message mock object.
This commit is contained in:
@@ -26,11 +26,11 @@ func StartRetentionScanner(ds DataStore) {
|
||||
expRetentionPeriod.Set(int64(cfg.RetentionMinutes * 60))
|
||||
if cfg.RetentionMinutes > 0 {
|
||||
// Retention scanning enabled
|
||||
log.Info("Retention configured for %v minutes", cfg.RetentionMinutes)
|
||||
log.LogInfo("Retention configured for %v minutes", cfg.RetentionMinutes)
|
||||
go retentionScanner(ds, time.Duration(cfg.RetentionMinutes) * time.Minute,
|
||||
time.Duration(cfg.RetentionSleep) * time.Millisecond)
|
||||
} else {
|
||||
log.Info("Retention scanner disabled")
|
||||
log.LogInfo("Retention scanner disabled")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,21 +41,21 @@ func retentionScanner(ds DataStore, maxAge time.Duration, sleep time.Duration) {
|
||||
since := time.Since(start)
|
||||
if since < time.Minute {
|
||||
dur := time.Minute - since
|
||||
log.Trace("Retention scanner sleeping for %v", dur)
|
||||
log.LogTrace("Retention scanner sleeping for %v", dur)
|
||||
time.Sleep(dur)
|
||||
}
|
||||
start = time.Now()
|
||||
|
||||
// Kickoff scan
|
||||
if err := doRetentionScan(ds, maxAge, sleep); err != nil {
|
||||
log.Error("Error during retention scan: %v", err)
|
||||
log.LogError("Error during retention scan: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// doRetentionScan does a single pass of all mailboxes looking for messages that can be purged
|
||||
func doRetentionScan(ds DataStore, maxAge time.Duration, sleep time.Duration) error {
|
||||
log.Trace("Starting retention scan")
|
||||
log.LogTrace("Starting retention scan")
|
||||
cutoff := time.Now().Add(-1 * maxAge)
|
||||
mboxes, err := ds.AllMailboxes()
|
||||
if err != nil {
|
||||
@@ -69,11 +69,11 @@ func doRetentionScan(ds DataStore, maxAge time.Duration, sleep time.Duration) er
|
||||
}
|
||||
for _, msg := range messages {
|
||||
if msg.Date().Before(cutoff) {
|
||||
log.Trace("Purging expired message %v", msg.Id())
|
||||
log.LogTrace("Purging expired message %v", msg.Id())
|
||||
err = msg.Delete()
|
||||
if err != nil {
|
||||
// Log but don't abort
|
||||
log.Error("Failed to purge message %v: %v", msg.Id(), err)
|
||||
log.LogError("Failed to purge message %v: %v", msg.Id(), err)
|
||||
} else {
|
||||
expRetentionDeletesTotal.Add(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user