engine

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package engine keeps resource data fresh, k9s-style: one poll goroutine per watched (profile, resource, scope) key feeding an in-memory cache, with results pushed to the UI through a sink (the app wires p.Send). Views render cached rows instantly (stale-while-revalidate) while the poller refreshes in the background.

The engine deliberately runs outside the Bubble Tea loop so cache entries outlive view pushes/pops and drill-back is instant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataEvent

type DataEvent struct {
	Key       Key
	Rows      []resource.Row
	Err       error
	FetchedAt time.Time
	Stale     bool
}

DataEvent is pushed to the sink after every fetch, and synchronously on Watch when cached rows exist. On fetch errors Rows retains the last good data (Stale=true) so views can keep rendering with a staleness badge.

type Engine

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

Engine owns the cache and poll goroutines.

func New

func New(sink func(DataEvent), store *Store) *Engine

New builds an engine delivering events to sink. The sink must be safe to call from any goroutine (tea.Program.Send is). A nil store disables the disk cache.

func (*Engine) RefreshNow

func (e *Engine) RefreshNow(key Key)

RefreshNow requests an immediate out-of-band fetch (ctrl+r). Non-blocking; coalesces if a refresh is already queued.

func (*Engine) Stop

func (e *Engine) Stop()

Stop cancels all pollers (app shutdown).

func (*Engine) Unwatch

func (e *Engine) Unwatch(key Key)

Unwatch drops one watcher; at zero the poll goroutine stops. The cache entry survives so the next Watch paints instantly.

func (*Engine) Watch

func (e *Engine) Watch(key Key, fetch FetchFunc, interval time.Duration)

Watch registers interest in a key. The first watcher starts the poll goroutine; if cached data exists it is delivered synchronously first, so re-entering a view paints instantly. Fetch and interval are only used when the key is not already being polled.

type FetchFunc

type FetchFunc func(ctx context.Context) ([]resource.Row, error)

FetchFunc loads rows for one key. Bound to a def+clients+scope by the caller; the engine knows nothing about resources or the SDK.

type Key

type Key struct {
	Profile  string
	Resource string
	Scope    string // resource.Scope.Hash()
}

Key identifies one cached dataset.

type Store

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

Store persists cache entries to disk so a fresh launch paints instantly from the last session's data (marked stale) while the poller refreshes in the background. Layout: <dir>/<profile>/<resource>[__scope].json.

func NewStore

func NewStore(dir string) *Store

NewStore roots a store at dir (usually $XDG_CACHE_HOME/lazydbx).

func (*Store) Load

func (s *Store) Load(k Key) (rows []resource.Row, fetchedAt time.Time, ok bool)

Load reads a cached entry; ok is false on miss or unreadable data. Row.Data round-trips through JSON, so loaded rows carry generic maps rather than the original domain structs — fine for describe rendering.

func (*Store) Save

func (s *Store) Save(k Key, rows []resource.Row, fetchedAt time.Time)

Save writes an entry atomically (temp file + rename); failures are logged and ignored — the disk cache is best-effort.

Jump to

Keyboard shortcuts

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