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 ¶
- type Registry
- func (r *Registry) All() []manifest.AppSpec
- func (r *Registry) Forget(stateFile string) error
- func (r *Registry) IsStopped(stateFile string) bool
- func (r *Registry) Managed(stateFile string) bool
- func (r *Registry) ManagedSpec(stateFile string) (manifest.AppSpec, bool)
- func (r *Registry) Remember(spec manifest.AppSpec) error
- func (r *Registry) Spec(stateFile string) (manifest.AppSpec, bool)
- func (r *Registry) Stop(stateFile string) error
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 Open ¶
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) Forget ¶
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 ¶
IsStopped reports whether the app at stateFile was explicitly stopped and hasn't been re-applied since.
func (*Registry) Managed ¶
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 ¶
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 ¶
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.