lifecycle

package
v1.76.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventUpdate = iota
	EventRemove
	EventSchedule
)

Event types determine context cancellation behavior in newContext.

Root events (EventUpdate, EventRemove) cancel the entire context tree and create a fresh root. All in-flight tasks for the package see ctx.Done().

Child events (EventSchedule) cancel only the previous context for the same event key, then create a new child of the current root.

EventSchedule is shared by both enable and disable flows, providing mutual cancellation: enabling cancels a pending disable and vice versa.

Variables

This section is empty.

Functions

This section is empty.

Types

type Package

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

Package holds the lifecycle state for a single runtime package: version tracking, pending settings, and a tree of cancellable contexts for coordinating concurrent operations.

Package does not hold the loaded runtime instance (Application/Module) — those live in plain maps on Runtime. This keeps the Store type-agnostic.

Context hierarchy:

root (ctx/cancel) — created by EventUpdate or EventRemove
└── EventSchedule child — cancelled on enable↔disable transition

type Store

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

Store manages lifecycle contexts and pending settings for all runtime packages. It is type-agnostic — it does not hold the loaded Application/Module instances, only the version, settings, and context tree needed for change detection and cancellation. The actual runtime instances live in plain maps on Runtime.

Store is not thread-safe; callers must hold Runtime.mu before calling any method.

func NewStore

func NewStore() *Store

NewStore creates an empty Store ready for use.

func (*Store) Delete

func (s *Store) Delete(name string) bool

Delete removes a package entry from the store if it still exists and is in the removed state (version cleared by HandleEvent(EventRemove)). Returns true if the entry was deleted.

Safe against re-creation races: if Update has already set a new version between the remove and this cleanup, the version is non-empty and Delete returns false, preserving the re-created entry.

func (*Store) GetPendingSettings added in v1.76.0

func (s *Store) GetPendingSettings(name string) addonutils.Values

GetPendingSettings returns the latest settings stored for a package. Called by schedulePackage to pass current settings into the Configure task. This late-binding approach ensures settings changes that arrive between Update and schedule are automatically picked up.

func (*Store) HandleEvent

func (s *Store) HandleEvent(event int, name string) context.Context

HandleEvent renews the context for the given event type and returns it.

For EventRemove: clears version and settings before renewing context, so a subsequent Update sees the package as new (enabling re-create after remove).

Returns nil if the package doesn't exist in the store.

func (*Store) NeedUpdate added in v1.76.0

func (s *Store) NeedUpdate(name, version, checksum string) bool

NeedUpdate reports whether the package needs processing: true if the package is new, the version changed, or the settings checksum differs. Used as a fast-path check before the more expensive Update call.

func (*Store) Update

func (s *Store) Update(name, version string, settings addonutils.Values) context.Context

Update registers a new package or processes a version change.

Returns a new root context (EventUpdate) when:

  1. Package not in store → creates entry, returns root context
  2. Version differs → cancels all in-flight tasks, returns new root context

Returns nil when only settings changed (no new context needed — settings are stored and will be picked up by the scheduler via GetPendingSettings on next Reschedule, or by the next Configure task in the schedule pipeline).

Callers should check for nil: a nil return with a settings-only change means the caller should trigger Reschedule to re-apply settings through the scheduler.

Jump to

Keyboard shortcuts

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