-
Notifications
You must be signed in to change notification settings - Fork 1
/
maintenance.go
64 lines (53 loc) · 1.29 KB
/
maintenance.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package database
import (
"context"
"time"
)
// Maintain runs the Maintain method on all storages.
func Maintain(ctx context.Context) (err error) {
// copy, as we might use the very long
all := duplicateControllers()
for _, c := range all {
err = c.Maintain(ctx)
if err != nil {
return
}
}
return
}
// MaintainThorough runs the MaintainThorough method on all storages.
func MaintainThorough(ctx context.Context) (err error) {
// copy, as we might use the very long
all := duplicateControllers()
for _, c := range all {
err = c.MaintainThorough(ctx)
if err != nil {
return
}
}
return
}
// MaintainRecordStates runs record state lifecycle maintenance on all storages.
func MaintainRecordStates(ctx context.Context) (err error) {
// delete immediately for now
// TODO: increase purge threshold when starting to sync DBs
purgeDeletedBefore := time.Now().UTC()
// copy, as we might use the very long
all := duplicateControllers()
for _, c := range all {
err = c.MaintainRecordStates(ctx, purgeDeletedBefore)
if err != nil {
return
}
}
return
}
func duplicateControllers() (all []*Controller) {
controllersLock.RLock()
defer controllersLock.RUnlock()
all = make([]*Controller, 0, len(controllers))
for _, c := range controllers {
all = append(all, c)
}
return
}