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