activitytracker

package
v0.0.0-...-80e4d6b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityTracker

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

ActivityTracker remembers active tasks in the file. If file already exists, it is recreated from scratch. Activity tracker uses mmap to write to the file, which allows fast writes because it's only using memory access, with no system calls. Nil activity tracker ignores all calls to its public API.

func NewActivityTracker

func NewActivityTracker(cfg Config, reg prometheus.Registerer) (*ActivityTracker, error)

func (*ActivityTracker) Close

func (t *ActivityTracker) Close() error

Close closes activity tracker. Calling other methods after Close() will likely panic. Don't do that.

func (*ActivityTracker) Delete

func (t *ActivityTracker) Delete(activityIndex int)

Delete removes activity with given index (returned previously by Insert) from the tracker. Should only be called once for each activity, as indexes are reused. It is OK to call Delete with negative index, which is returned by Insert when activity couldn't be inserted.

func (*ActivityTracker) Insert

func (t *ActivityTracker) Insert(activityGenerator func() string) (activityIndex int)

Insert inserts entry (generated by activityGenerator) into the activity tracker. If tracker is full, activityGenerator is not called. Value returned by Insert is to be used with Delete method after activity has finished.

String returned by activityGenerator should be human-readable description of activity. If it is bigger than max entry size, it will be trimmed on latest utf-8 rune start before the limit.

Note that timestamp of Insert call is stored automatically with the tracked activity.

func (*ActivityTracker) InsertStatic

func (t *ActivityTracker) InsertStatic(activity string) (activityIndex int)

type Config

type Config struct {
	Filepath   string `yaml:"filepath"`
	MaxEntries int    `yaml:"max_entries" category:"advanced"`
}

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(f *flag.FlagSet)

type Entry

type Entry struct {
	Timestamp time.Time
	Activity  string
}

Entry describes activity in the tracker.

func LoadUnfinishedEntries

func LoadUnfinishedEntries(file string) ([]Entry, error)

LoadUnfinishedEntries loads and returns list of unfinished activities in the activity file.

Jump to

Keyboard shortcuts

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