health

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Type of the event
	Type EventType

	// TaskID is the Docker Swarm task ID
	TaskID string

	// ServiceID is the Docker Swarm service ID
	ServiceID string

	// ServiceName is the human-readable service name
	ServiceName string

	// ContainerID is the container ID (if available)
	ContainerID string

	// NodeID is the node where task is running
	NodeID string

	// Timestamp when the event occurred
	Timestamp time.Time

	// State is the current task state (e.g., "running", "failed")
	State string

	// DesiredState is the desired task state (e.g., "running", "shutdown")
	DesiredState string

	// Message contains additional event details
	Message string

	// Error contains error information if event is failure-related
	Error error
}

Event represents a task lifecycle event

func (*Event) IsFailure

func (e *Event) IsFailure() bool

IsFailure returns true if the event represents a failure

func (*Event) IsHealthRelated

func (e *Event) IsHealthRelated() bool

IsHealthRelated returns true if the event is related to health checks

func (*Event) IsTerminal

func (e *Event) IsTerminal() bool

IsTerminal returns true if the event represents a terminal state (task will not transition to another state)

type EventType

type EventType string

EventType represents the type of task event

const (
	// EventTypeCreated is emitted when a new task is created
	EventTypeCreated EventType = "task_created"

	// EventTypeStarted is emitted when a task container starts
	EventTypeStarted EventType = "task_started"

	// EventTypeRunning is emitted when a task is confirmed running
	EventTypeRunning EventType = "task_running"

	// EventTypeHealthy is emitted when a task becomes healthy
	EventTypeHealthy EventType = "task_healthy"

	// EventTypeUnhealthy is emitted when a task becomes unhealthy
	EventTypeUnhealthy EventType = "task_unhealthy"

	// EventTypeFailed is emitted when a task fails
	EventTypeFailed EventType = "task_failed"

	// EventTypeCompleted is emitted when a task completes successfully
	EventTypeCompleted EventType = "task_completed"

	// EventTypeShutdown is emitted when a task is being shut down
	EventTypeShutdown EventType = "task_shutdown"
)

type Monitor

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

Monitor monitors a single task's lifecycle, health, and logs It automatically cleans up goroutines when task reaches terminal state

func NewMonitor

func NewMonitor(client client.APIClient, taskID string, serviceID string, serviceName string) *Monitor

NewMonitor creates a new task monitor

func NewMonitorWithLogs

func NewMonitorWithLogs(client client.APIClient, taskID string, serviceID string, serviceName string, showLogs bool) *Monitor

NewMonitorWithLogs creates a new task monitor with optional log streaming

func (*Monitor) Done

func (m *Monitor) Done() <-chan struct{}

Done returns a channel that is closed when monitor stops

func (*Monitor) GetState

func (m *Monitor) GetState() (state, desiredState, health string)

GetState returns current task state (thread-safe)

func (*Monitor) GetStats

func (m *Monitor) GetStats() (healthChecks, failedChecks int, lastSeen time.Time)

GetStats returns monitoring statistics

func (*Monitor) IsHealthy

func (m *Monitor) IsHealthy() bool

IsHealthy returns true if task is currently healthy

func (*Monitor) SendEvent

func (m *Monitor) SendEvent(event Event) bool

SendEvent sends an event to this task monitor Returns false if monitor is shutting down

func (*Monitor) Start

func (m *Monitor) Start(ctx context.Context) error

Start begins monitoring the task This method blocks until task reaches terminal state or context is cancelled

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop signals the monitor to stop

func (*Monitor) WaitForHealthy

func (m *Monitor) WaitForHealthy(timeout time.Duration) error

WaitForHealthy waits until task becomes healthy or times out

type ServiceUpdateMonitor

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

ServiceUpdateMonitor monitors service update status by polling ServiceInspect This is separate from task monitoring - it tracks overall service update progress

func NewServiceUpdateMonitor

func NewServiceUpdateMonitor(client client.APIClient, serviceID string, serviceName string) *ServiceUpdateMonitor

NewServiceUpdateMonitor creates a monitor for service update status

func (*ServiceUpdateMonitor) GetUpdateStatus

func (m *ServiceUpdateMonitor) GetUpdateStatus(ctx context.Context) (*swarm.UpdateStatus, error)

GetUpdateStatus returns current update status without blocking

func (*ServiceUpdateMonitor) WaitForUpdateComplete

func (m *ServiceUpdateMonitor) WaitForUpdateComplete(ctx context.Context) error

WaitForUpdateComplete blocks until service update reaches terminal state Returns nil if update completed successfully, error otherwise

type Watcher

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

Watcher monitors Docker events and emits task lifecycle events

func NewServiceWatcher

func NewServiceWatcher(client client.APIClient, stackName string, serviceID string, minVersion uint64, deployID string) *Watcher

NewServiceWatcher creates a task watcher filtered for specific service, version and deployID Only tasks with version >= minVersion AND matching deployID for this serviceID will emit events

func NewWatcher

func NewWatcher(client client.APIClient, stackName string) *Watcher

NewWatcher creates a new task event watcher for entire stack

func (*Watcher) CleanupOldTasks

func (w *Watcher) CleanupOldTasks(maxAge time.Duration) int

CleanupOldTasks removes task states that haven't been seen recently This prevents memory leaks from accumulating old task data

func (*Watcher) GetTaskState

func (w *Watcher) GetTaskState(taskID string) (state string, desiredState string, exists bool)

GetTaskState returns current state of a task (if tracked)

func (*Watcher) GetTasksForService

func (w *Watcher) GetTasksForService(serviceID string) []string

GetTasksForService returns all currently tracked tasks for a specific service

func (*Watcher) GetTrackedTasks

func (w *Watcher) GetTrackedTasks() []string

GetTrackedTasks returns all currently tracked task IDs

func (*Watcher) InspectTask

func (w *Watcher) InspectTask(ctx context.Context, taskID string) (*swarm.Task, error)

InspectTask fetches detailed task information from Docker API

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context) error

Start begins watching for task events This method blocks until context is cancelled

func (*Watcher) Subscribe

func (w *Watcher) Subscribe() <-chan Event

Subscribe returns a channel that receives task events The returned channel should be consumed continuously to avoid blocking Call Unsubscribe when done to clean up resources

func (*Watcher) SubscribeToService

func (w *Watcher) SubscribeToService(serviceID string) <-chan Event

SubscribeToService creates a filtered channel that only receives events for a specific service

func (*Watcher) Unsubscribe

func (w *Watcher) Unsubscribe(ch <-chan Event)

Unsubscribe removes a subscriber channel

Jump to

Keyboard shortcuts

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