github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/box_audit_scheduler_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/libkb"
    11  )
    12  
    13  var BoxAuditSchedulerBackgroundSettings = BackgroundTaskSettings{
    14  	Start:        2 * time.Minute,
    15  	StartStagger: 2 * time.Minute,
    16  	WakeUp:       1 * time.Minute,
    17  	Interval:     27 * time.Hour,
    18  	Limit:        15 * time.Minute,
    19  }
    20  
    21  type BoxAuditSchedulerBackground struct {
    22  	libkb.Contextified
    23  	sync.Mutex
    24  
    25  	task *BackgroundTask
    26  }
    27  
    28  func NewBoxAuditSchedulerBackground(g *libkb.GlobalContext) *BoxAuditSchedulerBackground {
    29  	task := NewBackgroundTask(g, &BackgroundTaskArgs{
    30  		Name:     "BoxAuditSchedulerBackground",
    31  		F:        BoxAuditSchedulerBackgroundRound,
    32  		Settings: BoxAuditSchedulerBackgroundSettings,
    33  	})
    34  	return &BoxAuditSchedulerBackground{
    35  		Contextified: libkb.NewContextified(g),
    36  		// Install the task early so that Shutdown can be called before RunEngine.
    37  		task: task,
    38  	}
    39  }
    40  
    41  func (e *BoxAuditSchedulerBackground) Name() string {
    42  	return "BoxAuditSchedulerBackground"
    43  }
    44  
    45  func (e *BoxAuditSchedulerBackground) Prereqs() Prereqs {
    46  	return Prereqs{}
    47  }
    48  
    49  func (e *BoxAuditSchedulerBackground) RequiredUIs() []libkb.UIKind {
    50  	return []libkb.UIKind{}
    51  }
    52  
    53  func (e *BoxAuditSchedulerBackground) SubConsumers() []libkb.UIConsumer {
    54  	return []libkb.UIConsumer{}
    55  }
    56  
    57  // Run starts the engine.
    58  // Returns immediately, kicks off a background goroutine.
    59  func (e *BoxAuditSchedulerBackground) Run(m libkb.MetaContext) (err error) {
    60  	return RunEngine2(m, e.task)
    61  }
    62  
    63  func (e *BoxAuditSchedulerBackground) Shutdown() {
    64  	e.task.Shutdown()
    65  }
    66  
    67  func BoxAuditSchedulerBackgroundRound(mctx libkb.MetaContext) error {
    68  	g := mctx.G()
    69  	if !g.ActiveDevice.Valid() {
    70  		mctx.Debug("BoxAuditSchedulerBackgroundRound; not logged in")
    71  		return nil
    72  	}
    73  
    74  	_, err := g.GetTeamBoxAuditor().BoxAuditRandomTeam(mctx)
    75  	return err
    76  }