Documentation
¶
Index ¶
- type Event
- type EventType
- type Monitor
- func (m *Monitor) Done() <-chan struct{}
- func (m *Monitor) GetState() (state, desiredState, health string)
- func (m *Monitor) GetStats() (healthChecks, failedChecks int, lastSeen time.Time)
- func (m *Monitor) IsHealthy() bool
- func (m *Monitor) SendEvent(event Event) bool
- func (m *Monitor) Start(ctx context.Context) error
- func (m *Monitor) Stop()
- func (m *Monitor) WaitForHealthy(timeout time.Duration) error
- type ServiceUpdateMonitor
- type Watcher
- func (w *Watcher) CleanupOldTasks(maxAge time.Duration) int
- func (w *Watcher) GetTaskState(taskID string) (state string, desiredState string, exists bool)
- func (w *Watcher) GetTasksForService(serviceID string) []string
- func (w *Watcher) GetTrackedTasks() []string
- func (w *Watcher) InspectTask(ctx context.Context, taskID string) (*swarm.Task, error)
- func (w *Watcher) Start(ctx context.Context) error
- func (w *Watcher) Subscribe() <-chan Event
- func (w *Watcher) SubscribeToService(serviceID string) <-chan Event
- func (w *Watcher) Unsubscribe(ch <-chan Event)
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) IsHealthRelated ¶
IsHealthRelated returns true if the event is related to health checks
func (*Event) IsTerminal ¶
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) SendEvent ¶
SendEvent sends an event to this task monitor Returns false if monitor is shutting down
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 ¶
NewWatcher creates a new task event watcher for entire stack
func (*Watcher) CleanupOldTasks ¶
CleanupOldTasks removes task states that haven't been seen recently This prevents memory leaks from accumulating old task data
func (*Watcher) GetTaskState ¶
GetTaskState returns current state of a task (if tracked)
func (*Watcher) GetTasksForService ¶
GetTasksForService returns all currently tracked tasks for a specific service
func (*Watcher) GetTrackedTasks ¶
GetTrackedTasks returns all currently tracked task IDs
func (*Watcher) InspectTask ¶
InspectTask fetches detailed task information from Docker API
func (*Watcher) Start ¶
Start begins watching for task events This method blocks until context is cancelled
func (*Watcher) Subscribe ¶
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 ¶
SubscribeToService creates a filtered channel that only receives events for a specific service
func (*Watcher) Unsubscribe ¶
Unsubscribe removes a subscriber channel