/
box_audit_scheduler_background.go
76 lines (61 loc) · 1.86 KB
/
box_audit_scheduler_background.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
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2019 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package engine
import (
"sync"
"time"
"github.com/keybase/client/go/libkb"
)
var BoxAuditSchedulerBackgroundSettings = BackgroundTaskSettings{
Start: 2 * time.Minute,
StartStagger: 2 * time.Minute,
WakeUp: 1 * time.Minute,
Interval: 27 * time.Hour,
Limit: 15 * time.Minute,
}
type BoxAuditSchedulerBackground struct {
libkb.Contextified
sync.Mutex
task *BackgroundTask
}
func NewBoxAuditSchedulerBackground(g *libkb.GlobalContext) *BoxAuditSchedulerBackground {
task := NewBackgroundTask(g, &BackgroundTaskArgs{
Name: "BoxAuditSchedulerBackground",
F: BoxAuditSchedulerBackgroundRound,
Settings: BoxAuditSchedulerBackgroundSettings,
})
return &BoxAuditSchedulerBackground{
Contextified: libkb.NewContextified(g),
// Install the task early so that Shutdown can be called before RunEngine.
task: task,
}
}
func (e *BoxAuditSchedulerBackground) Name() string {
return "BoxAuditSchedulerBackground"
}
func (e *BoxAuditSchedulerBackground) Prereqs() Prereqs {
return Prereqs{}
}
func (e *BoxAuditSchedulerBackground) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{}
}
func (e *BoxAuditSchedulerBackground) SubConsumers() []libkb.UIConsumer {
return []libkb.UIConsumer{}
}
// Run starts the engine.
// Returns immediately, kicks off a background goroutine.
func (e *BoxAuditSchedulerBackground) Run(m libkb.MetaContext) (err error) {
return RunEngine2(m, e.task)
}
func (e *BoxAuditSchedulerBackground) Shutdown() {
e.task.Shutdown()
}
func BoxAuditSchedulerBackgroundRound(mctx libkb.MetaContext) error {
g := mctx.G()
if !g.ActiveDevice.Valid() {
mctx.Debug("BoxAuditSchedulerBackgroundRound; not logged in")
return nil
}
_, err := g.GetTeamBoxAuditor().BoxAuditRandomTeam(mctx)
return err
}