-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
cleanup.go
40 lines (32 loc) · 801 Bytes
/
cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils
import (
"time"
"strconv"
"context"
"go.mongodb.org/mongo-driver/bson"
)
type CleanupObject struct {
Date time.Time
}
func CleanupByDate(collectionName string) {
c, errCo := GetCollection(GetRootAppId(), collectionName)
if errCo != nil {
MajorError("Database Cleanup", errCo)
return
}
del, err := c.DeleteMany(context.Background(), bson.M{"Date": bson.M{"$lt": time.Now().AddDate(0, -1, 0)}})
if err != nil {
MajorError("Database Cleanup", err)
return
}
Log("Cleanup: " + collectionName + " " + strconv.Itoa(int(del.DeletedCount)) + " objects deleted")
TriggerEvent(
"cosmos.database.cleanup",
"Database Cleanup of " + collectionName,
"success",
"",
map[string]interface{}{
"collection": collectionName,
"deleted": del.DeletedCount,
})
}