workspaceusage

package
v2.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFlushInterval = 60 * time.Second

Functions

This section is empty.

Types

type Option

type Option func(*Tracker)

func WithFlushInterval

func WithFlushInterval(d time.Duration) Option

WithFlushInterval allows configuring the flush interval of Tracker.

func WithLogger

func WithLogger(log slog.Logger) Option

WithLogger sets the logger to be used by Tracker.

func WithTickFlush

func WithTickFlush(tickCh <-chan time.Time, flushCh chan int) Option

WithTickFlush allows passing two channels: one that reads a time.Time, and one that returns the number of marked workspaces every time Tracker flushes. For testing only and will panic if used outside of tests.

type Store

type Store interface {
	BatchUpdateWorkspaceLastUsedAt(context.Context, database.BatchUpdateWorkspaceLastUsedAtParams) error
}

Store is a subset of database.Store

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker tracks and de-bounces updates to workspace usage activity. It keeps an internal map of workspace IDs that have been used and periodically flushes this to its configured Store.

func New

func New(s Store, opts ...Option) *Tracker

New returns a new Tracker. It is the caller's responsibility to call Close().

func (*Tracker) Add

func (tr *Tracker) Add(workspaceID uuid.UUID)

Add marks the workspace with the given ID as having been used recently. Tracker will periodically flush this to its configured Store.

func (*Tracker) Close

func (tr *Tracker) Close() error

Close stops Tracker and returns once Loop has exited. After calling Close(), Loop must not be called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL