1// Copyright 2019 Keybase, Inc. All rights reserved. Use of 2// this source code is governed by the included BSD license. 3 4package engine 5 6import ( 7 "sync" 8 "time" 9 10 "github.com/keybase/client/go/libkb" 11) 12 13var BoxAuditRetryBackgroundSettings = BackgroundTaskSettings{ 14 Start: 2 * time.Minute, 15 StartStagger: 1 * time.Minute, 16 WakeUp: 1 * time.Minute, 17 Interval: 7 * time.Hour, 18 Limit: 15 * time.Minute, 19} 20 21type BoxAuditRetryBackground struct { 22 libkb.Contextified 23 sync.Mutex 24 25 task *BackgroundTask 26} 27 28func NewBoxAuditRetryBackground(g *libkb.GlobalContext) *BoxAuditRetryBackground { 29 task := NewBackgroundTask(g, &BackgroundTaskArgs{ 30 Name: "BoxAuditRetryBackground", 31 F: BoxAuditRetryBackgroundRound, 32 Settings: BoxAuditRetryBackgroundSettings, 33 }) 34 return &BoxAuditRetryBackground{ 35 Contextified: libkb.NewContextified(g), 36 // Install the task early so that Shutdown can be called before RunEngine. 37 task: task, 38 } 39} 40 41func (e *BoxAuditRetryBackground) Name() string { 42 return "BoxAuditRetryBackground" 43} 44 45func (e *BoxAuditRetryBackground) Prereqs() Prereqs { 46 return Prereqs{} 47} 48 49func (e *BoxAuditRetryBackground) RequiredUIs() []libkb.UIKind { 50 return []libkb.UIKind{} 51} 52 53func (e *BoxAuditRetryBackground) SubConsumers() []libkb.UIConsumer { 54 return []libkb.UIConsumer{} 55} 56 57// Run starts the engine. 58// Returns immediately, kicks off a background goroutine. 59func (e *BoxAuditRetryBackground) Run(m libkb.MetaContext) (err error) { 60 return RunEngine2(m, e.task) 61} 62 63func (e *BoxAuditRetryBackground) Shutdown() { 64 e.task.Shutdown() 65} 66 67func BoxAuditRetryBackgroundRound(mctx libkb.MetaContext) error { 68 g := mctx.G() 69 if !g.ActiveDevice.Valid() { 70 mctx.Debug("BoxAuditRetryBackgroundRound; not logged in") 71 return nil 72 } 73 74 _, err := g.GetTeamBoxAuditor().RetryNextBoxAudit(mctx) 75 return err 76} 77