statemanager

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const OperationIDKey = "operation_id"

ContextKey for storing operation ID in echo context

Variables

This section is empty.

Functions

func GetOperationID

func GetOperationID(c echo.Context) string

GetOperationID retrieves the operation ID from the echo context Returns empty string if not found

Types

type Config

type Config struct {
	ServiceName   string
	MaxOperations int // Keep last N operations, default 1000
}

Config for creating a new Manager

type Manager

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

Manager handles state tracking for operations

func New

func New(cfg Config) *Manager

New creates a new state manager

func (*Manager) CompleteOperation

func (m *Manager) CompleteOperation(id string, err error)

CompleteOperation marks an operation as completed or failed

func (*Manager) GetOperation

func (m *Manager) GetOperation(id string) *OperationState

GetOperation retrieves an operation by ID

func (*Manager) GetStats

func (m *Manager) GetStats() *OperationStats

GetStats returns aggregated statistics

func (*Manager) ListOperations

func (m *Manager) ListOperations() []*OperationState

ListOperations returns all tracked operations

func (*Manager) Middleware

func (m *Manager) Middleware(operationType string) echo.MiddlewareFunc

Middleware creates Echo middleware for automatic operation tracking Usage: e.Use(stateManager.Middleware("operation-type"))

func (*Manager) RegisterRoutes

func (m *Manager) RegisterRoutes(g *echo.Group)

RegisterRoutes adds state endpoints to an Echo group

func (*Manager) StartOperation

func (m *Manager) StartOperation(id, operation string, metadata map[string]interface{}) *OperationState

StartOperation creates a new operation in running state

func (*Manager) UpdateMetadata

func (m *Manager) UpdateMetadata(id string, key string, value interface{})

UpdateMetadata adds/updates metadata for an operation

type OperationState

type OperationState struct {
	ID          string                 `json:"id"`
	ServiceName string                 `json:"service_name"`
	Operation   string                 `json:"operation"` // e.g., "xquery", "s3-upload", "template-render"
	Status      Status                 `json:"status"`
	StartedAt   time.Time              `json:"started_at"`
	CompletedAt *time.Time             `json:"completed_at,omitempty"`
	Duration    string                 `json:"duration,omitempty"`
	Error       string                 `json:"error,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"` // Service-specific data
}

OperationState represents a tracked operation

type OperationStats

type OperationStats struct {
	TotalOperations int            `json:"total_operations"`
	ByStatus        map[Status]int `json:"by_status"`
	ByOperation     map[string]int `json:"by_operation"`
	AverageDuration string         `json:"average_duration,omitempty"`
}

OperationStats provides aggregated statistics

type Status

type Status string

Status represents the state of an operation

const (
	StatusPending   Status = "pending"
	StatusRunning   Status = "running"
	StatusCompleted Status = "completed"
	StatusFailed    Status = "failed"
	StatusTimeout   Status = "timeout"
)

Jump to

Keyboard shortcuts

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