github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/engine/box_audit_retry_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 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  
    21  type BoxAuditRetryBackground struct {
    22  	libkb.Contextified
    23  	sync.Mutex
    24  
    25  	task *BackgroundTask
    26  }
    27  
    28  func 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  
    41  func (e *BoxAuditRetryBackground) Name() string {
    42  	return "BoxAuditRetryBackground"
    43  }
    44  
    45  func (e *BoxAuditRetryBackground) Prereqs() Prereqs {
    46  	return Prereqs{}
    47  }
    48  
    49  func (e *BoxAuditRetryBackground) RequiredUIs() []libkb.UIKind {
    50  	return []libkb.UIKind{}
    51  }
    52  
    53  func (e *BoxAuditRetryBackground) 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 *BoxAuditRetryBackground) Run(m libkb.MetaContext) (err error) {
    60  	return RunEngine2(m, e.task)
    61  }
    62  
    63  func (e *BoxAuditRetryBackground) Shutdown() {
    64  	e.task.Shutdown()
    65  }
    66  
    67  func 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  }