-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.go
63 lines (53 loc) · 1.31 KB
/
status.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
package main
import (
"time"
"go.uber.org/atomic"
log "github.com/sirupsen/logrus"
)
type Status struct {
deletedCount atomic.Uint64
errorCount atomic.Uint64
lastDeletedKey atomic.String
}
func (s *Status) Update(addDeleted int, lastKey string) {
if addDeleted > 0 {
s.deletedCount.Add(uint64(addDeleted))
}
s.lastDeletedKey.Store(lastKey)
}
func (s *Status) IncrementErrors() uint64 {
return s.errorCount.Inc()
}
func (s *Status) Display(period time.Duration, done <-chan bool) {
ticker := time.NewTicker(period)
keepGoing := true
log.WithFields(log.Fields{
"deleted": s.deletedCount.Load(),
"errors": s.errorCount.Load(),
"last_object": s.lastDeletedKey.Load(),
}).Info("Status")
var oldDelete, oldErr uint64
for keepGoing {
select {
case <-ticker.C:
newDelete, newErr := s.deletedCount.Load(), s.errorCount.Load()
if newDelete == oldDelete && newErr == oldErr {
continue
}
log.WithFields(log.Fields{
"deleted": newDelete,
"errors": newErr,
"last_object": s.lastDeletedKey.Load(),
}).Info("Status")
oldDelete, oldErr = newDelete, newErr
case <-done:
ticker.Stop()
keepGoing = false
}
}
log.WithFields(log.Fields{
"deleted": s.deletedCount.Load(),
"errors": s.errorCount.Load(),
"last_object": s.lastDeletedKey.Load(),
}).Info("Done")
}