registry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package registry remembers which apps shinyctl-api manages: the last applied spec of each and whether it was stopped on purpose. It is kept in a file, so a restarted shinyctl-api goes on watching what the previous one watched and does not bring back what the user took down.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry remembers the most recently applied spec for each app, keyed by its state file path, so the background reconcile loop has something to check even when no client is actively asking about it right now. It also tracks which apps have been explicitly stopped, so the reconcile loop knows not to bring them back up.

Opened with a path, it writes through to disk on every change and reloads from there on the next Open — so a restarted shinyctl-api resumes watching everything the previous one was watching, instead of coming back knowing nothing until someone re-applies. The stopped flags persist too: a restart must not resurrect what the user deliberately took down.

It's accessed from at least two goroutines — an HTTP handler goroutine per request, and the ticker-driven reconcile loop — so every access needs the mutex; a map is not safe for concurrent use on its own.

func New

func New() *Registry

New returns an in-memory Registry that persists nothing.

func Open

func Open(path string) (*Registry, error)

Open returns a Registry backed by the file at path, loading whatever a previous shinyctl-api left there. A missing file is an empty registry; an unreadable or malformed one is an error, not silently empty — a fresh start that quietly forgets every app is the exact failure this persistence exists to prevent.

func (*Registry) All

func (r *Registry) All() []manifest.AppSpec

All returns every spec currently remembered.

func (*Registry) Forget

func (r *Registry) Forget(stateFile string) error

Forget drops every record of the app at stateFile — its spec and any stopped flag — so it no longer appears in status and nothing will ever restart it. The next Remember (apply) starts it from scratch. Forgetting an unknown app is a no-op, not an error.

func (*Registry) IsStopped

func (r *Registry) IsStopped(stateFile string) bool

IsStopped reports whether the app at stateFile was explicitly stopped and hasn't been re-applied since.

func (*Registry) Managed

func (r *Registry) Managed(stateFile string) bool

Managed reports whether the reconcile loop should be keeping the app at stateFile running: remembered, and not stopped. This — not IsStopped — is what the ticker and the exit-watchers gate on, so that an app that's been Forget-ten is left alone exactly like a stopped one, instead of being restarted by the exit-watcher of the very process delete killed.

func (*Registry) ManagedSpec

func (r *Registry) ManagedSpec(stateFile string) (manifest.AppSpec, bool)

ManagedSpec is Managed plus the remembered spec, read in one step so the two can't disagree. The second result is false if the app is unknown or stopped.

func (*Registry) Remember

func (r *Registry) Remember(spec manifest.AppSpec) error

Remember records spec as the latest desired state for its app, overwriting whatever was previously remembered for the same state file. It also clears any prior Stop — applying an app is a declaration that it should be running, so it un-stops whatever was stopped before.

func (*Registry) Spec

func (r *Registry) Spec(stateFile string) (manifest.AppSpec, bool)

Spec returns the spec remembered for stateFile, whether or not it is stopped. stop and delete need it after they have marked the app stopped.

func (*Registry) Stop

func (r *Registry) Stop(stateFile string) error

Stop marks the app at stateFile as intentionally stopped — the reconcile loop must not restart it until it's Remember-ed (re-applied) again.

Jump to

Keyboard shortcuts

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