servicecommands

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 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"

	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