servicecommands

package
v0.5.81 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package servicecommands stores small, allowlisted service control requests.

Index

Constants

View Source
const (
	ActionRestart = "restart"
	// ActionPersistConfig asks a service to write its DB-edited config
	// sections back to its own YAML file. Unlike a restart it does not
	// change what the running process is using — only what is on disk.
	ActionPersistConfig = "persist-config"
	// ActionReloadLogSinks asks osctrl-tls to rebuild its per-environment
	// log sink exporter map from the log_sinks table and swap it in
	// without restarting. In-flight logs to the old sinks may be dropped
	// during the swap; the old sinks are closed immediately after the
	// new set is live.
	ActionReloadLogSinks = "reload-log-sinks"
	// ActionReloadAuthProviders asks osctrl-api to rebuild its
	// auth provider registry from the auth_providers table and swap
	// it in without restarting. Users mid-login may see a transient
	// error and can retry.
	ActionReloadAuthProviders = "reload-auth-providers"
	// ActionReloadAlerts asks osctrl-tls to reload its alert rule
	// snapshot and reset the channel sender cache without restarting.
	// The swap is atomic (copy-on-write snapshot), so in-flight matches
	// finish against the old ruleset while new logs pick up the new one.
	ActionReloadAlerts = "reload-alerts"

	StatusPending   = "pending"
	StatusConsumed  = "consumed"
	StatusRecovered = "recovered"
	StatusExpired   = "expired"
)

Variables

View Source
var (
	ErrInvalidTarget = errors.New("invalid service command target")
	ErrInvalidAction = errors.New("invalid service command action")
)

Functions

This section is empty.

Types

type Manager

type Manager struct {
	DB *gorm.DB
}

Manager manages service_commands.

func NewManager

func NewManager(db *gorm.DB) *Manager

func (*Manager) ConsumeNext

func (m *Manager) ConsumeNext(targetService, consumedBy string, now time.Time) (ServiceCommand, bool, error)

ConsumeNext claims the oldest pending command for the service, whatever its action. The caller dispatches on cmd.Action — actions are allowlisted at request time, so anything returned here is one the consumer knows.

func (*Manager) Get

func (m *Manager) Get(commandID string) (ServiceCommand, error)

func (*Manager) MarkRecovered

func (m *Manager) MarkRecovered(targetService, recoveredBy string, now time.Time) (int64, error)

func (*Manager) Request

func (m *Manager) Request(targetService, action, requestedBy, requestedFrom string, ttl time.Duration) (ServiceCommand, error)

Request enqueues a one-shot command for a service to consume on its next poll.

func (*Manager) RequestRestart

func (m *Manager) RequestRestart(targetService, requestedBy, requestedFrom string, ttl time.Duration) (ServiceCommand, error)

type ServiceCommand

type ServiceCommand struct {
	gorm.Model
	CommandID     string `gorm:"uniqueIndex"`
	TargetService string `gorm:"index:idx_service_commands_pending"`
	Action        string `gorm:"index:idx_service_commands_pending"`
	RequestedBy   string
	RequestedFrom string
	ConsumedAt    *time.Time `gorm:"index:idx_service_commands_pending"`
	ConsumedBy    string
	RecoveredAt   *time.Time
	RecoveredBy   string
	ExpiresAt     time.Time `gorm:"index:idx_service_commands_pending"`
}

ServiceCommand is a one-shot control request for another osctrl service.

func (ServiceCommand) Status

func (c ServiceCommand) Status(now time.Time) string

Status derives the operator-facing command status.

Jump to

Keyboard shortcuts

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