workercache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package workercache maintains an in-memory view of all workers, kept current via store.Interface.WatchWorkers. It exposes Workers() for fast O(1) reads during actor scheduling and is the natural home for future indices (by node, by label, etc.) as scheduling requirements grow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache maintains an in-memory snapshot of all workers.

TODO: add metrics — at minimum a gauge for worker count, a counter for resync events, and a counter for failed worker-watch notifications.

func New

func New(store workerListWatcher, relistInterval time.Duration) *Cache

New creates a Cache backed by a given store. relistInterval controls how often the cache performs a full ListWorkers to recover from state drifts caused by missing WorkerWatch events.

func (*Cache) Forget

func (c *Cache) Forget(name string)

Forget removes a worker that a store write proved no longer exists. The normal delete watch remains authoritative, but this closes the short race in which scheduling selected a worker just after its row was deleted and before the watch event reached the cache.

func (*Cache) Start

func (c *Cache) Start(ctx context.Context) error

Start syncs the cache synchronously, then spawns a background goroutine that streams updates, relists periodically, and resyncs on connection loss. Returns as soon as the initial sync succeeds.

func (*Cache) Worker

func (c *Cache) Worker(name string) (*ateapipb.Worker, error)

Worker returns the worker with the given name.

func (*Cache) Workers

func (c *Cache) Workers() ([]*ateapipb.Worker, error)

Workers returns a snapshot of all currently known workers. The returned slice and its elements must not be modified by the caller. Returns an error if the cache is not ready (brief window during reconnect); callers are expected to retry.

Jump to

Keyboard shortcuts

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