core

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Exit codes for swarm service execution states
	// These are Ofelia-specific codes, not from Docker Swarm API
	// They indicate failure modes that don't map to container exit codes
	ExitCodeSwarmError = -999 // Swarm orchestration error (task not found, service unavailable)
	ExitCodeTimeout    = -998 // Max runtime exceeded before task completion
)
View Source
const HashmeTagName = "hash"

Variables

View Source
var (
	// Container errors
	ErrContainerNotFound     = errors.New("container not found")
	ErrContainerStartFailed  = errors.New("failed to start container")
	ErrContainerCreateFailed = errors.New("failed to create container")
	ErrContainerStopFailed   = errors.New("failed to stop container")
	ErrContainerRemoveFailed = errors.New("failed to remove container")

	// Image errors
	ErrImageNotFound      = errors.New("image not found")
	ErrImagePullFailed    = errors.New("failed to pull image")
	ErrLocalImageNotFound = errors.New("local image not found")

	// Service errors
	ErrServiceNotFound     = errors.New("service not found")
	ErrServiceCreateFailed = errors.New("failed to create service")
	ErrServiceStartFailed  = errors.New("failed to start service")
	ErrServiceRemoveFailed = errors.New("failed to remove service")

	// Job errors
	ErrJobNotFound      = errors.New("job not found")
	ErrJobAlreadyExists = errors.New("job already exists")
	ErrJobExecution     = errors.New("job execution failed")
	ErrMaxTimeRunning   = errors.New("max runtime exceeded")
	ErrUnexpected       = errors.New("unexpected error")

	// Workflow errors
	ErrCircularDependency = errors.New("circular dependency detected")
	ErrDependencyNotMet   = errors.New("job dependencies not met")
	ErrWorkflowInvalid    = errors.New("invalid workflow configuration")
)

Common errors used across the package

View Source
var (
	ErrEmptyScheduler = errors.New("unable to start an empty scheduler")
	ErrEmptySchedule  = errors.New("unable to add a job with an empty schedule")
)
View Source
var (
	// DefaultBufferPool provides enhanced performance for job execution
	// This replaces the simple buffer pool with multi-tier adaptive pooling
	// Note: ShrinkInterval is set to 0 to prevent background goroutine at package init
	DefaultBufferPool = func() *EnhancedBufferPool {
		cfg := DefaultEnhancedBufferPoolConfig()
		cfg.ShrinkInterval = 0
		cfg.EnablePrewarming = false
		cfg.PoolSize = 0
		return NewEnhancedBufferPool(cfg, nil)
	}()
)

Global enhanced buffer pool instance

View Source
var ErrSkippedExecution = errors.New("skipped execution")

ErrSkippedExecution pass this error to `Execution.Stop` if you wish to mark it as skipped.

View Source
var GlobalPerformanceMetrics = NewPerformanceMetrics()

Global enhanced metrics instance

View Source
var Version = "dev"

Version is the Ofelia version, set via ldflags during build. Defaults to "dev" if not set.

Functions

func GetHash added in v0.10.1

func GetHash(t reflect.Type, v reflect.Value, hash *string) error

func IsNonZeroExitError added in v0.10.1

func IsNonZeroExitError(err error) bool

IsNonZeroExitError checks if the error is a non-zero exit code error

func IsRetryableError added in v0.10.1

func IsRetryableError(err error) bool

IsRetryableError checks if an error should trigger a retry

func Retry added in v0.10.1

func Retry(ctx context.Context, policy *RetryPolicy, fn func() error) error

Retry executes a function with retry logic

func SetGlobalBufferPoolLogger added in v0.11.0

func SetGlobalBufferPoolLogger(logger Logger)

SetGlobalBufferPoolLogger sets the logger for the global buffer pool

func WrapContainerError added in v0.10.1

func WrapContainerError(op string, containerID string, err error) error

WrapContainerError wraps a container-related error with context

func WrapImageError added in v0.10.1

func WrapImageError(op string, image string, err error) error

WrapImageError wraps an image-related error with context

func WrapJobError added in v0.10.1

func WrapJobError(op string, jobName string, err error) error

WrapJobError wraps a job-related error with context

func WrapServiceError added in v0.10.1

func WrapServiceError(op string, serviceID string, err error) error

WrapServiceError wraps a service-related error with context

Types

type BareJob

type BareJob struct {
	Schedule         string   `hash:"true"`
	Name             string   `hash:"true"`
	Command          string   `hash:"true"`
	HistoryLimit     int      `default:"10"`
	MaxRetries       int      `default:"0"`     // Maximum number of retry attempts (0 = no retries)
	RetryDelayMs     int      `default:"1000"`  // Initial retry delay in milliseconds
	RetryExponential bool     `default:"true"`  // Use exponential backoff for retries
	RetryMaxDelayMs  int      `default:"60000"` // Maximum retry delay in milliseconds (1 minute)
	Dependencies     []string // Names of jobs that must complete successfully before this job
	OnSuccess        []string // Jobs to trigger on successful completion
	OnFailure        []string // Jobs to trigger on failure
	AllowParallel    bool     `default:"true"` // Allow job to run in parallel with others
	// contains filtered or unexported fields
}

func (*BareJob) GetCommand

func (j *BareJob) GetCommand() string

func (*BareJob) GetCronJobID

func (j *BareJob) GetCronJobID() int

func (*BareJob) GetHistory added in v0.8.0

func (j *BareJob) GetHistory() []*Execution

GetHistory returns a copy of the job's execution history.

func (*BareJob) GetLastRun added in v0.8.0

func (j *BareJob) GetLastRun() *Execution

GetLastRun returns the last execution of the job, if any.

func (*BareJob) GetName

func (j *BareJob) GetName() string

func (*BareJob) GetRetryConfig added in v0.10.1

func (j *BareJob) GetRetryConfig() RetryConfig

GetRetryConfig returns the retry configuration for the job

func (*BareJob) GetSchedule

func (j *BareJob) GetSchedule() string

func (*BareJob) Hash

func (j *BareJob) Hash() (string, error)

Returns a hash of all the job attributes. Used to detect changes

func (*BareJob) Middlewares

func (c *BareJob) Middlewares() []Middleware

func (*BareJob) NotifyStart

func (j *BareJob) NotifyStart()

func (*BareJob) NotifyStop

func (j *BareJob) NotifyStop()

func (*BareJob) ResetMiddlewares added in v0.9.0

func (c *BareJob) ResetMiddlewares(ms ...Middleware)

func (*BareJob) Run added in v0.10.1

func (j *BareJob) Run(ctx *Context) error

Run implements the Job interface - this is handled by jobWrapper

func (*BareJob) Running

func (j *BareJob) Running() int32

func (*BareJob) SetCronJobID

func (j *BareJob) SetCronJobID(id int)

func (*BareJob) SetLastRun added in v0.8.0

func (j *BareJob) SetLastRun(e *Execution)

SetLastRun stores the last executed run for the job.

func (*BareJob) Use

func (c *BareJob) Use(ms ...Middleware)

type Bulkhead added in v0.10.1

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

Bulkhead implements the bulkhead pattern for resource isolation

func NewBulkhead added in v0.10.1

func NewBulkhead(name string, maxConcurrent int) *Bulkhead

NewBulkhead creates a new bulkhead

func (*Bulkhead) Execute added in v0.10.1

func (b *Bulkhead) Execute(ctx context.Context, fn func() error) error

Execute runs a function with bulkhead protection

func (*Bulkhead) GetMetrics added in v0.10.1

func (b *Bulkhead) GetMetrics() map[string]interface{}

GetMetrics returns bulkhead metrics

type CircuitBreaker added in v0.10.1

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

CircuitBreaker implements the circuit breaker pattern

func NewCircuitBreaker added in v0.10.1

func NewCircuitBreaker(name string, maxFailures uint32, resetTimeout time.Duration) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker

func (*CircuitBreaker) Execute added in v0.10.1

func (cb *CircuitBreaker) Execute(fn func() error) error

Execute runs a function through the circuit breaker

func (*CircuitBreaker) GetMetrics added in v0.10.1

func (cb *CircuitBreaker) GetMetrics() map[string]interface{}

GetMetrics returns circuit breaker metrics

func (*CircuitBreaker) GetState added in v0.10.1

func (cb *CircuitBreaker) GetState() CircuitBreakerState

GetState returns the current state of the circuit breaker

type CircuitBreakerState added in v0.10.1

type CircuitBreakerState int

CircuitBreakerState represents the state of a circuit breaker

const (
	StateClosed CircuitBreakerState = iota
	StateOpen
	StateHalfOpen
)

func (CircuitBreakerState) String added in v0.10.1

func (s CircuitBreakerState) String() string

type ComposeJob added in v0.9.0

type ComposeJob struct {
	BareJob `mapstructure:",squash"`
	File    string `default:"compose.yml" gcfg:"file" mapstructure:"file" hash:"true"`
	Service string `gcfg:"service" mapstructure:"service" hash:"true"`
	Exec    bool   `default:"false" gcfg:"exec" mapstructure:"exec" hash:"true"`
}

func NewComposeJob added in v0.9.0

func NewComposeJob() *ComposeJob

func (*ComposeJob) Middlewares added in v0.9.0

func (c *ComposeJob) Middlewares() []Middleware

func (*ComposeJob) ResetMiddlewares added in v0.9.0

func (c *ComposeJob) ResetMiddlewares(ms ...Middleware)

func (*ComposeJob) Run added in v0.9.0

func (j *ComposeJob) Run(ctx *Context) error

func (*ComposeJob) Use added in v0.9.0

func (c *ComposeJob) Use(ms ...Middleware)

type ContainerLifecycle added in v0.10.1

type ContainerLifecycle struct {
	*DockerOperations
}

ContainerLifecycle provides container lifecycle management operations

func (*ContainerLifecycle) CreateContainer added in v0.10.1

func (cl *ContainerLifecycle) CreateContainer(opts docker.CreateContainerOptions) (*docker.Container, error)

CreateContainer creates a container with consistent error handling

func (*ContainerLifecycle) InspectContainer added in v0.10.1

func (cl *ContainerLifecycle) InspectContainer(containerID string) (*docker.Container, error)

InspectContainer inspects a container with consistent error handling

func (*ContainerLifecycle) RemoveContainer added in v0.10.1

func (cl *ContainerLifecycle) RemoveContainer(containerID string, force bool) error

RemoveContainer removes a container with consistent error handling

func (*ContainerLifecycle) StartContainer added in v0.10.1

func (cl *ContainerLifecycle) StartContainer(containerID string, hostConfig *docker.HostConfig) error

StartContainer starts a container with consistent error handling and metrics

func (*ContainerLifecycle) StopContainer added in v0.10.1

func (cl *ContainerLifecycle) StopContainer(containerID string, timeout uint) error

StopContainer stops a container with timeout and consistent error handling

type ContainerMonitor added in v0.10.1

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

ContainerMonitor provides efficient container monitoring using Docker events

func NewContainerMonitor added in v0.10.1

func NewContainerMonitor(client *docker.Client, logger Logger) *ContainerMonitor

NewContainerMonitor creates a new container monitor

func (*ContainerMonitor) MonitorContainerLogs added in v0.10.1

func (cm *ContainerMonitor) MonitorContainerLogs(containerID string, stdout, stderr bool) error

MonitorContainerLogs streams container logs efficiently

func (*ContainerMonitor) SetMetricsRecorder added in v0.10.1

func (cm *ContainerMonitor) SetMetricsRecorder(recorder MetricsRecorder)

SetMetricsRecorder sets the metrics recorder for monitoring metrics

func (*ContainerMonitor) SetUseEventsAPI added in v0.10.1

func (cm *ContainerMonitor) SetUseEventsAPI(use bool)

SetUseEventsAPI allows toggling between events API and polling (for compatibility)

func (*ContainerMonitor) WaitForContainer added in v0.10.1

func (cm *ContainerMonitor) WaitForContainer(containerID string, maxRuntime time.Duration) (*docker.State, error)

WaitForContainer waits for a container to complete using the most efficient method available

type Context

type Context struct {
	Scheduler *Scheduler
	Logger    Logger
	Job       Job
	Execution *Execution
	// contains filtered or unexported fields
}

func NewContext

func NewContext(s *Scheduler, j Job, e *Execution) *Context

func (*Context) Log

func (c *Context) Log(msg string)

func (*Context) Next

func (c *Context) Next() error

func (*Context) Start

func (c *Context) Start()

func (*Context) Stop

func (c *Context) Stop(err error)

func (*Context) Warn

func (c *Context) Warn(msg string)

type CronUtils

type CronUtils struct {
	Logger Logger
}

Implement the cron logger interface

func NewCronUtils

func NewCronUtils(l Logger) *CronUtils

func (*CronUtils) Error

func (c *CronUtils) Error(err error, msg string, keysAndValues ...interface{})

func (*CronUtils) Info

func (c *CronUtils) Info(msg string, keysAndValues ...interface{})

type DependencyNode added in v0.10.1

type DependencyNode struct {
	Job          Job
	Dependencies []string // Job names this job depends on
	Dependents   []string // Job names that depend on this job
	OnSuccess    []string // Jobs to trigger on success
	OnFailure    []string // Jobs to trigger on failure
}

DependencyNode represents a job in the dependency graph

type DockerCircuitBreaker added in v0.11.0

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

DockerCircuitBreaker implements a simple circuit breaker pattern for Docker API calls

func NewDockerCircuitBreaker added in v0.11.0

func NewDockerCircuitBreaker(config *DockerClientConfig, logger Logger) *DockerCircuitBreaker

NewDockerCircuitBreaker creates a new circuit breaker

func (*DockerCircuitBreaker) Execute added in v0.11.0

func (cb *DockerCircuitBreaker) Execute(fn func() error) error

Execute runs the given function if the circuit breaker allows it

type DockerCircuitBreakerState added in v0.11.0

type DockerCircuitBreakerState int

DockerCircuitBreakerState represents the state of the circuit breaker

const (
	DockerCircuitClosed DockerCircuitBreakerState = iota
	DockerCircuitOpen
	DockerCircuitHalfOpen
)

type DockerClientConfig added in v0.11.0

type DockerClientConfig struct {
	// Connection pooling settings
	MaxIdleConns        int           `json:"maxIdleConns"`
	MaxIdleConnsPerHost int           `json:"maxIdleConnsPerHost"`
	MaxConnsPerHost     int           `json:"maxConnsPerHost"`
	IdleConnTimeout     time.Duration `json:"idleConnTimeout"`

	// Timeouts
	DialTimeout           time.Duration `json:"dialTimeout"`
	ResponseHeaderTimeout time.Duration `json:"responseHeaderTimeout"`
	RequestTimeout        time.Duration `json:"requestTimeout"`

	// Circuit breaker settings
	EnableCircuitBreaker  bool          `json:"enableCircuitBreaker"`
	FailureThreshold      int           `json:"failureThreshold"`
	RecoveryTimeout       time.Duration `json:"recoveryTimeout"`
	MaxConcurrentRequests int           `json:"maxConcurrentRequests"`
}

DockerClientConfig holds configuration for the optimized Docker client

func DefaultDockerClientConfig added in v0.11.0

func DefaultDockerClientConfig() *DockerClientConfig

DefaultDockerClientConfig returns sensible defaults for high-performance Docker operations

type DockerOperations added in v0.10.1

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

DockerOperations provides a high-level interface for common Docker operations with consistent error handling and logging

func NewDockerOperations added in v0.10.1

func NewDockerOperations(client *docker.Client, logger Logger, metricsRecorder MetricsRecorder) *DockerOperations

NewDockerOperations creates a new Docker operations wrapper

func (*DockerOperations) NewContainerLifecycle added in v0.10.1

func (d *DockerOperations) NewContainerLifecycle() *ContainerLifecycle

NewContainerLifecycle creates a new container lifecycle manager

func (*DockerOperations) NewExecOperations added in v0.10.1

func (d *DockerOperations) NewExecOperations() *ExecOperations

NewExecOperations creates a new exec operations manager

func (*DockerOperations) NewImageOperations added in v0.10.1

func (d *DockerOperations) NewImageOperations() *ImageOperations

NewImageOperations creates a new image operations manager

func (*DockerOperations) NewLogsOperations added in v0.10.1

func (d *DockerOperations) NewLogsOperations() *LogsOperations

NewLogsOperations creates a new logs operations manager

func (*DockerOperations) NewNetworkOperations added in v0.10.1

func (d *DockerOperations) NewNetworkOperations() *NetworkOperations

NewNetworkOperations creates a new network operations manager

type EnhancedBufferPool added in v0.11.0

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

EnhancedBufferPool provides high-performance buffer management with adaptive sizing

func NewBufferPool added in v0.10.1

func NewBufferPool(minSize, defaultSize, maxSize int64) *EnhancedBufferPool

NewBufferPool is a compatibility wrapper for tests and old code It returns the enhanced buffer pool with custom configuration

func NewEnhancedBufferPool added in v0.11.0

func NewEnhancedBufferPool(config *EnhancedBufferPoolConfig, logger Logger) *EnhancedBufferPool

NewEnhancedBufferPool creates a new enhanced buffer pool with adaptive management

func (*EnhancedBufferPool) Get added in v0.11.0

func (ebp *EnhancedBufferPool) Get() (*circbuf.Buffer, error)

Get retrieves a buffer from the pool, optimized for high concurrency

func (*EnhancedBufferPool) GetSized added in v0.11.0

func (ebp *EnhancedBufferPool) GetSized(requestedSize int64) (*circbuf.Buffer, error)

GetSized retrieves a buffer with a specific size requirement, with intelligent size selection

func (*EnhancedBufferPool) GetStats added in v0.11.0

func (ebp *EnhancedBufferPool) GetStats() map[string]interface{}

GetStats returns comprehensive performance statistics

func (*EnhancedBufferPool) Put added in v0.11.0

func (ebp *EnhancedBufferPool) Put(buf *circbuf.Buffer)

Put returns a buffer to the appropriate pool

func (*EnhancedBufferPool) Shutdown added in v0.11.0

func (ebp *EnhancedBufferPool) Shutdown()

Shutdown gracefully stops the enhanced buffer pool

type EnhancedBufferPoolConfig added in v0.11.0

type EnhancedBufferPoolConfig struct {
	MinSize          int64         `json:"minSize"`          // Minimum buffer size
	DefaultSize      int64         `json:"defaultSize"`      // Default buffer size
	MaxSize          int64         `json:"maxSize"`          // Maximum buffer size
	PoolSize         int           `json:"poolSize"`         // Number of buffers to pre-allocate
	MaxPoolSize      int           `json:"maxPoolSize"`      // Maximum number of buffers in pool
	GrowthFactor     float64       `json:"growthFactor"`     // Factor to increase pool size when needed
	ShrinkThreshold  float64       `json:"shrinkThreshold"`  // Usage percentage below which to shrink
	ShrinkInterval   time.Duration `json:"shrinkInterval"`   // How often to check for shrinking
	EnableMetrics    bool          `json:"enableMetrics"`    // Enable performance metrics
	EnablePrewarming bool          `json:"enablePrewarming"` // Pre-allocate buffers on startup
}

EnhancedBufferPoolConfig holds configuration for the enhanced buffer pool

func DefaultEnhancedBufferPoolConfig added in v0.11.0

func DefaultEnhancedBufferPoolConfig() *EnhancedBufferPoolConfig

DefaultEnhancedBufferPoolConfig returns optimized defaults for high-concurrency scenarios

type ExecJob

type ExecJob struct {
	BareJob     `mapstructure:",squash"`
	Client      *docker.Client `json:"-"`
	Container   string         `hash:"true"`
	User        string         `default:"nobody" hash:"true"`
	TTY         bool           `default:"false" hash:"true"`
	Environment []string       `mapstructure:"environment" hash:"true"`
	WorkingDir  string         `mapstructure:"working-dir" hash:"true"`
	// contains filtered or unexported fields
}

func NewExecJob

func NewExecJob(c *docker.Client) *ExecJob

func (*ExecJob) InitializeRuntimeFields added in v0.10.2

func (j *ExecJob) InitializeRuntimeFields()

InitializeRuntimeFields initializes fields that depend on the Docker client This should be called after the Client field is set, typically during configuration loading

func (*ExecJob) Middlewares

func (c *ExecJob) Middlewares() []Middleware

func (*ExecJob) ResetMiddlewares added in v0.9.0

func (c *ExecJob) ResetMiddlewares(ms ...Middleware)

func (*ExecJob) Run

func (j *ExecJob) Run(ctx *Context) error

func (*ExecJob) Use

func (c *ExecJob) Use(ms ...Middleware)

type ExecOperations added in v0.10.1

type ExecOperations struct {
	*DockerOperations
}

ExecOperations provides container exec operations with consistent error handling

func (*ExecOperations) CreateExec added in v0.10.1

func (eo *ExecOperations) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error)

CreateExec creates an exec instance with consistent error handling and metrics

func (*ExecOperations) InspectExec added in v0.10.1

func (eo *ExecOperations) InspectExec(execID string) (*docker.ExecInspect, error)

InspectExec inspects an exec instance with consistent error handling

func (*ExecOperations) StartExec added in v0.10.1

func (eo *ExecOperations) StartExec(execID string, opts docker.StartExecOptions) error

StartExec starts an exec instance with consistent error handling and metrics

type Execution

type Execution struct {
	ID        string
	Date      time.Time
	Duration  time.Duration
	IsRunning bool
	Failed    bool
	Skipped   bool
	Error     error

	OutputStream, ErrorStream *circbuf.Buffer `json:"-"`

	// Captured output for persistence after buffer cleanup
	CapturedStdout, CapturedStderr string `json:"-"`
}

Execution contains all the information relative to a Job execution.

func NewExecution

func NewExecution() (*Execution, error)

NewExecution returns a new Execution, with a random ID

func (*Execution) Cleanup added in v0.10.1

func (e *Execution) Cleanup()

Cleanup returns execution buffers to the pool for reuse

func (*Execution) GetStderr added in v0.10.1

func (e *Execution) GetStderr() string

GetStderr returns stderr content, preferring live buffer if available

func (*Execution) GetStdout added in v0.10.1

func (e *Execution) GetStdout() string

GetStdout returns stdout content, preferring live buffer if available

func (*Execution) Start

func (e *Execution) Start()

Start starts the execution, initializes the running flags and the start date.

func (*Execution) Stop

func (e *Execution) Stop(err error)

Stop halts the execution. If a ErrSkippedExecution is given the execution is marked as skipped; if any other error is given the execution is marked as failed. Also mark the execution as IsRunning false and save the duration time

type GracefulScheduler added in v0.10.1

type GracefulScheduler struct {
	*Scheduler
	// contains filtered or unexported fields
}

GracefulScheduler wraps a scheduler with graceful shutdown

func NewGracefulScheduler added in v0.10.1

func NewGracefulScheduler(scheduler *Scheduler, shutdownManager *ShutdownManager) *GracefulScheduler

NewGracefulScheduler creates a scheduler with graceful shutdown support

func (GracefulScheduler) Middlewares added in v0.10.1

func (c GracefulScheduler) Middlewares() []Middleware

func (GracefulScheduler) ResetMiddlewares added in v0.10.1

func (c GracefulScheduler) ResetMiddlewares(ms ...Middleware)

func (*GracefulScheduler) RunJobWithTracking added in v0.10.1

func (gs *GracefulScheduler) RunJobWithTracking(job Job, ctx *Context) error

RunJobWithTracking runs a job with shutdown tracking

func (GracefulScheduler) Use added in v0.10.1

func (c GracefulScheduler) Use(ms ...Middleware)

type GracefulServer added in v0.10.1

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

GracefulServer wraps an HTTP server with graceful shutdown

func NewGracefulServer added in v0.10.1

func NewGracefulServer(server *http.Server, shutdownManager *ShutdownManager, logger Logger) *GracefulServer

NewGracefulServer creates a server with graceful shutdown support

type ImageOperations added in v0.10.1

type ImageOperations struct {
	*DockerOperations
}

ImageOperations provides image management operations

func (*ImageOperations) EnsureImage added in v0.10.1

func (imgOps *ImageOperations) EnsureImage(image string, forcePull bool) error

EnsureImage ensures an image is available locally, pulling if necessary

func (*ImageOperations) HasImageLocally added in v0.10.1

func (imgOps *ImageOperations) HasImageLocally(image string) (bool, error)

HasImageLocally checks if an image exists locally

func (*ImageOperations) ListImages added in v0.10.1

func (imgOps *ImageOperations) ListImages(image string) ([]docker.APIImages, error)

ListImages lists images matching the given image name

func (*ImageOperations) PullImage added in v0.10.1

func (imgOps *ImageOperations) PullImage(image string) error

PullImage pulls an image with authentication and consistent error handling

type Job

type Job interface {
	GetName() string
	GetSchedule() string
	GetCommand() string
	Middlewares() []Middleware
	Use(...Middleware)
	Run(*Context) error
	Running() int32
	NotifyStart()
	NotifyStop()
	GetCronJobID() int
	SetCronJobID(int)
	GetHistory() []*Execution
	Hash() (string, error)
}

type JobMetrics added in v0.11.0

type JobMetrics struct {
	ExecutionCount  int64
	TotalDuration   time.Duration
	AverageDuration time.Duration
	MinDuration     time.Duration
	MaxDuration     time.Duration
	SuccessCount    int64
	FailureCount    int64
	LastExecution   time.Time
	LastSuccess     time.Time
	LastFailure     time.Time
}

JobMetrics holds metrics for individual jobs

type JobMetricsRecorder added in v0.10.1

type JobMetricsRecorder interface {
	RecordMetric(name string, value interface{})
	RecordJobExecution(jobName string, success bool, duration time.Duration)
	RecordRetryAttempt(jobName string, attempt int, success bool)
}

JobMetricsRecorder interface for recording job-specific metrics

type LatencyTracker added in v0.11.0

type LatencyTracker struct {
	Count   int64
	Total   time.Duration
	Min     time.Duration
	Max     time.Duration
	Average time.Duration
	// contains filtered or unexported fields
}

LatencyTracker tracks latency statistics for operations

type LocalJob

type LocalJob struct {
	BareJob     `mapstructure:",squash"`
	Dir         string   `hash:"true"`
	Environment []string `mapstructure:"environment" hash:"true"`
}

func NewLocalJob

func NewLocalJob() *LocalJob

func (*LocalJob) Middlewares

func (c *LocalJob) Middlewares() []Middleware

func (*LocalJob) ResetMiddlewares added in v0.9.0

func (c *LocalJob) ResetMiddlewares(ms ...Middleware)

func (*LocalJob) Run

func (j *LocalJob) Run(ctx *Context) error

func (*LocalJob) Use

func (c *LocalJob) Use(ms ...Middleware)

type Logger

type Logger interface {
	Criticalf(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Noticef(format string, args ...interface{})
	Warningf(format string, args ...interface{})
}

type LogrusAdapter added in v0.8.0

type LogrusAdapter struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

LogrusAdapter wraps a logrus.Logger to satisfy the Logger interface.

func (*LogrusAdapter) Criticalf added in v0.8.0

func (l *LogrusAdapter) Criticalf(format string, args ...interface{})

func (*LogrusAdapter) Debugf added in v0.8.0

func (l *LogrusAdapter) Debugf(format string, args ...interface{})

func (*LogrusAdapter) Errorf added in v0.8.0

func (l *LogrusAdapter) Errorf(format string, args ...interface{})

func (*LogrusAdapter) Noticef added in v0.8.0

func (l *LogrusAdapter) Noticef(format string, args ...interface{})

func (*LogrusAdapter) Warningf added in v0.8.0

func (l *LogrusAdapter) Warningf(format string, args ...interface{})

type LogsOperations added in v0.10.1

type LogsOperations struct {
	*DockerOperations
}

LogsOperations provides container log operations

func (*LogsOperations) GetLogs added in v0.10.1

func (lo *LogsOperations) GetLogs(containerID string, opts docker.LogsOptions) error

GetLogs retrieves container logs with consistent error handling

func (*LogsOperations) GetLogsSince added in v0.10.1

func (lo *LogsOperations) GetLogsSince(
	containerID string, since time.Time, stdout, stderr bool, outputStream, errorStream io.Writer,
) error

GetLogsSince retrieves container logs since a specific time

type MetricsRecorder added in v0.10.1

type MetricsRecorder interface {
	RecordJobRetry(jobName string, attempt int, success bool)
	RecordContainerEvent()
	RecordContainerMonitorFallback()
	RecordContainerMonitorMethod(usingEvents bool)
	RecordContainerWaitDuration(seconds float64)
	RecordDockerOperation(operation string)
	RecordDockerError(operation string)
}

MetricsRecorder interface for recording retry and monitoring metrics

type Middleware

type Middleware interface {
	// Run is called instead of the original `Job.Run`, you MUST call to `ctx.Run`
	// inside of the middleware `Run` function otherwise you will broken the
	// Job workflow.
	Run(*Context) error
	// ContinueOnStop reports whether Run should be called even when the
	// execution has been stopped
	ContinueOnStop() bool
}

Middleware can wrap any job execution, allowing to execution code before or/and after of each `Job.Run`

type MockDockerClient added in v0.10.1

type MockDockerClient struct {
	*docker.Client
	// contains filtered or unexported fields
}

MockDockerClient provides a test double for Docker client operations

func NewMockDockerClient added in v0.10.1

func NewMockDockerClient() *MockDockerClient

func (*MockDockerClient) CreateContainer added in v0.10.1

func (m *MockDockerClient) CreateContainer(opts docker.CreateContainerOptions) (*docker.Container, error)

func (*MockDockerClient) CreateExec added in v0.10.1

func (m *MockDockerClient) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error)

Exec operations

func (*MockDockerClient) InspectContainerWithOptions added in v0.10.1

func (m *MockDockerClient) InspectContainerWithOptions(opts docker.InspectContainerOptions) (*docker.Container, error)

Container operations

func (*MockDockerClient) InspectExec added in v0.10.1

func (m *MockDockerClient) InspectExec(execID string) (*docker.ExecInspect, error)

func (*MockDockerClient) InspectImage added in v0.10.1

func (m *MockDockerClient) InspectImage(name string) (*docker.Image, error)

Image operations

func (*MockDockerClient) Logs added in v0.10.1

func (m *MockDockerClient) Logs(opts docker.LogsOptions) error

func (*MockDockerClient) PullImage added in v0.10.1

func (*MockDockerClient) RemoveContainer added in v0.10.1

func (m *MockDockerClient) RemoveContainer(opts docker.RemoveContainerOptions) error

func (*MockDockerClient) StartContainer added in v0.10.1

func (m *MockDockerClient) StartContainer(id string, hostConfig *docker.HostConfig) error

func (*MockDockerClient) StartExec added in v0.10.1

func (m *MockDockerClient) StartExec(execID string, opts docker.StartExecOptions) error

type MockLogger added in v0.10.1

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

MockLogger for testing

func (*MockLogger) Criticalf added in v0.10.1

func (m *MockLogger) Criticalf(format string, args ...interface{})

func (*MockLogger) Debugf added in v0.10.1

func (m *MockLogger) Debugf(format string, args ...interface{})

func (*MockLogger) Errorf added in v0.10.1

func (m *MockLogger) Errorf(format string, args ...interface{})

func (*MockLogger) Noticef added in v0.10.1

func (m *MockLogger) Noticef(format string, args ...interface{})

func (*MockLogger) Warningf added in v0.10.1

func (m *MockLogger) Warningf(format string, args ...interface{})

type NetworkOperations added in v0.10.1

type NetworkOperations struct {
	*DockerOperations
}

NetworkOperations provides network management operations

func (*NetworkOperations) ConnectContainerToNetwork added in v0.10.1

func (no *NetworkOperations) ConnectContainerToNetwork(containerID, networkID string) error

ConnectContainerToNetwork connects a container to a network

func (*NetworkOperations) FindNetworkByName added in v0.10.1

func (no *NetworkOperations) FindNetworkByName(networkName string) ([]docker.Network, error)

FindNetworkByName finds a network by name

type NonZeroExitError added in v0.10.1

type NonZeroExitError struct {
	ExitCode int
}

NonZeroExitError represents a container exit with non-zero code

func (NonZeroExitError) Error added in v0.10.1

func (e NonZeroExitError) Error() string

type OptimizedDockerClient added in v0.11.0

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

OptimizedDockerClient wraps the Docker client with performance optimizations

func NewOptimizedDockerClient added in v0.11.0

func NewOptimizedDockerClient(config *DockerClientConfig, logger Logger, metrics PerformanceRecorder) (*OptimizedDockerClient, error)

NewOptimizedDockerClient creates a new Docker client with performance optimizations

func (*OptimizedDockerClient) AddEventListenerWithOptions added in v0.11.0

func (c *OptimizedDockerClient) AddEventListenerWithOptions(opts docker.EventsOptions, listener chan<- *docker.APIEvents) error

AddEventListenerWithOptions wraps event listening (delegates to underlying client)

func (*OptimizedDockerClient) Close added in v0.11.0

func (c *OptimizedDockerClient) Close() error

Close closes the optimized Docker client and cleans up resources

func (*OptimizedDockerClient) CreateContainer added in v0.11.0

CreateContainer wraps container creation with optimizations

func (*OptimizedDockerClient) GetClient added in v0.11.0

func (c *OptimizedDockerClient) GetClient() *docker.Client

GetClient returns the underlying Docker client

func (*OptimizedDockerClient) GetStats added in v0.11.0

func (c *OptimizedDockerClient) GetStats() map[string]interface{}

GetStats returns performance statistics about the optimized client

func (*OptimizedDockerClient) Info added in v0.11.0

Info wraps the Docker Info call with circuit breaker and metrics

func (*OptimizedDockerClient) ListContainers added in v0.11.0

ListContainers wraps the Docker ListContainers call with optimizations

func (*OptimizedDockerClient) StartContainer added in v0.11.0

func (c *OptimizedDockerClient) StartContainer(id string, hostConfig *docker.HostConfig) error

StartContainer wraps container start with optimizations

func (*OptimizedDockerClient) StopContainer added in v0.11.0

func (c *OptimizedDockerClient) StopContainer(id string, timeout uint) error

StopContainer wraps container stop with optimizations

type PerformanceMetrics added in v0.11.0

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

PerformanceMetrics implements comprehensive performance tracking

func NewPerformanceMetrics added in v0.11.0

func NewPerformanceMetrics() *PerformanceMetrics

NewPerformanceMetrics creates a new performance metrics recorder

func (*PerformanceMetrics) GetDockerMetrics added in v0.11.0

func (pm *PerformanceMetrics) GetDockerMetrics() map[string]interface{}

GetDockerMetrics returns Docker-specific metrics

func (*PerformanceMetrics) GetJobMetrics added in v0.11.0

func (pm *PerformanceMetrics) GetJobMetrics() map[string]interface{}

GetJobMetrics returns job execution metrics

func (*PerformanceMetrics) GetMetrics added in v0.11.0

func (pm *PerformanceMetrics) GetMetrics() map[string]interface{}

GetMetrics returns all performance metrics

func (*PerformanceMetrics) GetSummaryReport added in v0.11.0

func (pm *PerformanceMetrics) GetSummaryReport() string

GetSummaryReport generates a human-readable performance summary

func (*PerformanceMetrics) RecordBufferPoolStats added in v0.11.0

func (pm *PerformanceMetrics) RecordBufferPoolStats(stats map[string]interface{})

RecordBufferPoolStats records buffer pool performance statistics

func (*PerformanceMetrics) RecordConcurrentJobs added in v0.11.0

func (pm *PerformanceMetrics) RecordConcurrentJobs(count int64)

RecordConcurrentJobs tracks the number of concurrent jobs

func (*PerformanceMetrics) RecordContainerEvent added in v0.11.0

func (pm *PerformanceMetrics) RecordContainerEvent()

RecordContainerEvent records container events

func (*PerformanceMetrics) RecordContainerMonitorFallback added in v0.11.0

func (pm *PerformanceMetrics) RecordContainerMonitorFallback()

RecordContainerMonitorFallback records container monitor fallbacks

func (*PerformanceMetrics) RecordContainerMonitorMethod added in v0.11.0

func (pm *PerformanceMetrics) RecordContainerMonitorMethod(usingEvents bool)

RecordContainerMonitorMethod records container monitor method usage

func (*PerformanceMetrics) RecordContainerWaitDuration added in v0.11.0

func (pm *PerformanceMetrics) RecordContainerWaitDuration(seconds float64)

RecordContainerWaitDuration records container wait durations

func (*PerformanceMetrics) RecordCustomMetric added in v0.11.0

func (pm *PerformanceMetrics) RecordCustomMetric(name string, value interface{})

RecordCustomMetric records a custom metric

func (*PerformanceMetrics) RecordDockerError added in v0.11.0

func (pm *PerformanceMetrics) RecordDockerError(operation string)

RecordDockerError records a Docker operation error

func (*PerformanceMetrics) RecordDockerLatency added in v0.11.0

func (pm *PerformanceMetrics) RecordDockerLatency(operation string, duration time.Duration)

RecordDockerLatency records the latency of a Docker operation

func (*PerformanceMetrics) RecordDockerOperation added in v0.11.0

func (pm *PerformanceMetrics) RecordDockerOperation(operation string)

RecordDockerOperation records a successful Docker operation

func (*PerformanceMetrics) RecordJobExecution added in v0.11.0

func (pm *PerformanceMetrics) RecordJobExecution(jobName string, duration time.Duration, success bool)

RecordJobExecution records a job execution with timing and success status

func (*PerformanceMetrics) RecordJobRetry added in v0.11.0

func (pm *PerformanceMetrics) RecordJobRetry(jobName string, attempt int, success bool)

RecordJobRetry records job retry attempts

func (*PerformanceMetrics) RecordJobScheduled added in v0.11.0

func (pm *PerformanceMetrics) RecordJobScheduled(jobName string)

RecordJobScheduled records when a job is scheduled

func (*PerformanceMetrics) RecordJobSkipped added in v0.11.0

func (pm *PerformanceMetrics) RecordJobSkipped(jobName string, reason string)

RecordJobSkipped records when a job is skipped

func (*PerformanceMetrics) RecordMemoryUsage added in v0.11.0

func (pm *PerformanceMetrics) RecordMemoryUsage(bytes int64)

RecordMemoryUsage tracks memory usage

func (*PerformanceMetrics) Reset added in v0.11.0

func (pm *PerformanceMetrics) Reset()

Reset clears all metrics (useful for testing or periodic resets)

type PerformanceRecorder added in v0.11.0

type PerformanceRecorder interface {
	MetricsRecorder // Embed existing interface (includes RecordDockerError)

	// Extended Docker operations
	RecordDockerLatency(operation string, duration time.Duration)

	// Job operations
	RecordJobExecution(jobName string, duration time.Duration, success bool)
	RecordJobScheduled(jobName string)
	RecordJobSkipped(jobName string, reason string)

	// System metrics
	RecordConcurrentJobs(count int64)
	RecordMemoryUsage(bytes int64)
	RecordBufferPoolStats(stats map[string]interface{})

	// Custom metrics
	RecordCustomMetric(name string, value interface{})

	// Retrieval
	GetMetrics() map[string]interface{}
	GetDockerMetrics() map[string]interface{}
	GetJobMetrics() map[string]interface{}
	Reset()
}

PerformanceRecorder defines the interface for recording comprehensive performance metrics This extends the existing MetricsRecorder interface with additional capabilities

type RateLimiter added in v0.10.1

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

RateLimiter implements token bucket rate limiting

func NewRateLimiter added in v0.10.1

func NewRateLimiter(rate float64, capacity int) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow added in v0.10.1

func (rl *RateLimiter) Allow() bool

Allow checks if a request is allowed

func (*RateLimiter) AllowN added in v0.10.1

func (rl *RateLimiter) AllowN(n int) bool

AllowN checks if n requests are allowed

func (*RateLimiter) Wait added in v0.10.1

func (rl *RateLimiter) Wait(ctx context.Context) error

Wait blocks until a request is allowed

func (*RateLimiter) WaitN added in v0.10.1

func (rl *RateLimiter) WaitN(ctx context.Context, n int) error

WaitN blocks until n requests are allowed

type ResilientJobExecutor added in v0.10.1

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

ResilientJobExecutor wraps job execution with resilience patterns

func NewResilientJobExecutor added in v0.10.1

func NewResilientJobExecutor(job Job) *ResilientJobExecutor

NewResilientJobExecutor creates a new resilient job executor

func (*ResilientJobExecutor) Execute added in v0.10.1

func (rje *ResilientJobExecutor) Execute(ctx *Context) error

Execute runs the job with resilience patterns

func (*ResilientJobExecutor) GetCircuitBreakerState added in v0.10.1

func (rje *ResilientJobExecutor) GetCircuitBreakerState() CircuitBreakerState

GetCircuitBreakerState returns the current state of the circuit breaker

func (*ResilientJobExecutor) ResetCircuitBreaker added in v0.10.1

func (rje *ResilientJobExecutor) ResetCircuitBreaker()

ResetCircuitBreaker manually resets the circuit breaker

func (*ResilientJobExecutor) SetBulkhead added in v0.10.1

func (rje *ResilientJobExecutor) SetBulkhead(bh *Bulkhead)

SetBulkhead updates the bulkhead

func (*ResilientJobExecutor) SetCircuitBreaker added in v0.10.1

func (rje *ResilientJobExecutor) SetCircuitBreaker(cb *CircuitBreaker)

SetCircuitBreaker updates the circuit breaker

func (*ResilientJobExecutor) SetMetricsRecorder added in v0.10.1

func (rje *ResilientJobExecutor) SetMetricsRecorder(metrics JobMetricsRecorder)

SetMetricsRecorder sets the metrics recorder

func (*ResilientJobExecutor) SetRateLimiter added in v0.10.1

func (rje *ResilientJobExecutor) SetRateLimiter(rl *RateLimiter)

SetRateLimiter updates the rate limiter

func (*ResilientJobExecutor) SetRetryPolicy added in v0.10.1

func (rje *ResilientJobExecutor) SetRetryPolicy(policy *RetryPolicy)

SetRetryPolicy updates the retry policy

type RetryConfig added in v0.10.1

type RetryConfig struct {
	MaxRetries       int
	RetryDelayMs     int
	RetryExponential bool
	RetryMaxDelayMs  int
}

RetryConfig contains retry configuration for a job

type RetryExecutor added in v0.10.1

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

RetryExecutor wraps job execution with retry logic

func NewRetryExecutor added in v0.10.1

func NewRetryExecutor(logger Logger) *RetryExecutor

NewRetryExecutor creates a new retry executor

func (*RetryExecutor) ExecuteWithRetry added in v0.10.1

func (re *RetryExecutor) ExecuteWithRetry(job Job, ctx *Context, runFunc func(*Context) error) error

ExecuteWithRetry executes a job with retry logic

func (*RetryExecutor) SetMetricsRecorder added in v0.10.1

func (re *RetryExecutor) SetMetricsRecorder(metrics MetricsRecorder)

SetMetricsRecorder sets the metrics recorder for the retry executor

type RetryMetrics added in v0.11.0

type RetryMetrics struct {
	TotalAttempts     int64
	SuccessfulRetries int64
	FailedRetries     int64
	LastRetry         time.Time
}

RetryMetrics holds retry-specific metrics

type RetryPolicy added in v0.10.1

type RetryPolicy struct {
	MaxAttempts     int
	InitialDelay    time.Duration
	MaxDelay        time.Duration
	BackoffFactor   float64
	JitterFactor    float64
	RetryableErrors func(error) bool
}

RetryPolicy defines retry behavior

func DefaultRetryPolicy added in v0.10.1

func DefaultRetryPolicy() *RetryPolicy

DefaultRetryPolicy returns a default retry policy

type RetryStats added in v0.10.1

type RetryStats struct {
	JobName       string
	TotalAttempts int
	SuccessAfter  int // Number of retries before success (0 if first attempt succeeded)
	Failed        bool
	LastError     error
}

RetryStats tracks retry statistics for a job

type RetryableJob added in v0.10.1

type RetryableJob interface {
	Job
	GetRetryConfig() RetryConfig
}

RetryableJob interface for jobs that support retries

type RunJob

type RunJob struct {
	BareJob `mapstructure:",squash"`
	Client  *docker.Client `json:"-"`

	User string `default:"nobody" hash:"true"`

	// ContainerName specifies the name of the container to be created. If
	// nil, the job name will be used. If set to an empty string, Docker
	// will assign a random name.
	ContainerName *string `gcfg:"container-name" mapstructure:"container-name" hash:"true"`

	TTY bool `default:"false" hash:"true"`

	// do not use bool values with "default:true" because if
	// user would set it to "false" explicitly, it still will be
	// changed to "true" https://github.com/netresearch/ofelia/issues/135
	// so lets use strings here as workaround
	Delete string `default:"true" hash:"true"`
	Pull   string `default:"true" hash:"true"`

	Image       string   `hash:"true"`
	Network     string   `hash:"true"`
	Hostname    string   `hash:"true"`
	Entrypoint  *string  `hash:"true"`
	Container   string   `hash:"true"`
	Volume      []string `hash:"true"`
	VolumesFrom []string `gcfg:"volumes-from" mapstructure:"volumes-from," hash:"true"`
	Environment []string `mapstructure:"environment" hash:"true"`
	Annotations []string `mapstructure:"annotations" hash:"true"`

	MaxRuntime time.Duration `gcfg:"max-runtime" mapstructure:"max-runtime"`
	// contains filtered or unexported fields
}

func NewRunJob

func NewRunJob(c *docker.Client) *RunJob

func (*RunJob) InitializeRuntimeFields added in v0.10.1

func (j *RunJob) InitializeRuntimeFields()

InitializeRuntimeFields initializes fields that depend on the Docker client This should be called after the Client field is set, typically during configuration loading

func (*RunJob) Middlewares

func (c *RunJob) Middlewares() []Middleware

func (*RunJob) ResetMiddlewares added in v0.9.0

func (c *RunJob) ResetMiddlewares(ms ...Middleware)

func (*RunJob) Run

func (j *RunJob) Run(ctx *Context) error

func (*RunJob) Use

func (c *RunJob) Use(ms ...Middleware)

type RunServiceJob

type RunServiceJob struct {
	BareJob `mapstructure:",squash"`
	Client  *docker.Client `json:"-"`
	User    string         `default:"nobody" hash:"true"`
	TTY     bool           `default:"false" hash:"true"`
	// do not use bool values with "default:true" because if
	// user would set it to "false" explicitly, it still will be
	// changed to "true" https://github.com/netresearch/ofelia/issues/135
	// so lets use strings here as workaround
	Delete      string        `default:"true" hash:"true"`
	Image       string        `hash:"true"`
	Network     string        `hash:"true"`
	Annotations []string      `mapstructure:"annotations" hash:"true"`
	MaxRuntime  time.Duration `gcfg:"max-runtime" mapstructure:"max-runtime"`
}

func NewRunServiceJob

func NewRunServiceJob(c *docker.Client) *RunServiceJob

func (*RunServiceJob) Middlewares

func (c *RunServiceJob) Middlewares() []Middleware

func (*RunServiceJob) ResetMiddlewares added in v0.9.0

func (c *RunServiceJob) ResetMiddlewares(ms ...Middleware)

func (*RunServiceJob) Run

func (j *RunServiceJob) Run(ctx *Context) error

func (*RunServiceJob) Use

func (c *RunServiceJob) Use(ms ...Middleware)

type Scheduler

type Scheduler struct {
	Jobs     []Job
	Removed  []Job
	Disabled []Job
	Logger   Logger
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(l Logger) *Scheduler

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(j Job) error

func (*Scheduler) DisableJob added in v0.8.0

func (s *Scheduler) DisableJob(name string) error

DisableJob stops scheduling the job but keeps it for later enabling.

func (*Scheduler) EnableJob added in v0.8.0

func (s *Scheduler) EnableJob(name string) error

EnableJob schedules a previously disabled job.

func (*Scheduler) Entries added in v0.8.0

func (s *Scheduler) Entries() []cron.Entry

Entries returns all scheduled cron entries.

func (*Scheduler) GetDisabledJob added in v0.8.0

func (s *Scheduler) GetDisabledJob(name string) Job

GetDisabledJob returns a disabled job by name.

func (*Scheduler) GetDisabledJobs added in v0.8.0

func (s *Scheduler) GetDisabledJobs() []Job

GetDisabledJobs returns a copy of all disabled jobs.

func (*Scheduler) GetJob added in v0.8.0

func (s *Scheduler) GetJob(name string) Job

GetJob returns an active job by name.

func (*Scheduler) GetRemovedJobs added in v0.8.0

func (s *Scheduler) GetRemovedJobs() []Job

GetRemovedJobs returns a copy of all jobs that were removed from the scheduler.

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

IsRunning returns true if the scheduler is active.

func (*Scheduler) Middlewares

func (c *Scheduler) Middlewares() []Middleware

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(j Job) error

func (*Scheduler) ResetMiddlewares added in v0.9.0

func (c *Scheduler) ResetMiddlewares(ms ...Middleware)

func (*Scheduler) RunJob added in v0.8.0

func (s *Scheduler) RunJob(jobName string) error

RunJob manually triggers a job by name

func (*Scheduler) SetMaxConcurrentJobs added in v0.10.1

func (s *Scheduler) SetMaxConcurrentJobs(maxJobs int)

SetMaxConcurrentJobs configures the maximum number of concurrent jobs

func (*Scheduler) SetMetricsRecorder added in v0.10.1

func (s *Scheduler) SetMetricsRecorder(recorder MetricsRecorder)

SetMetricsRecorder sets the metrics recorder for the scheduler

func (*Scheduler) Start

func (s *Scheduler) Start() error

func (*Scheduler) Stop

func (s *Scheduler) Stop() error

func (*Scheduler) Use

func (c *Scheduler) Use(ms ...Middleware)

type ShutdownHook added in v0.10.1

type ShutdownHook struct {
	Name     string
	Priority int // Lower values execute first
	Hook     func(context.Context) error
}

ShutdownHook is a function to be called during shutdown

type ShutdownManager added in v0.10.1

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

ShutdownManager handles graceful shutdown of the application

func NewShutdownManager added in v0.10.1

func NewShutdownManager(logger Logger, timeout time.Duration) *ShutdownManager

NewShutdownManager creates a new shutdown manager

func (*ShutdownManager) IsShuttingDown added in v0.10.1

func (sm *ShutdownManager) IsShuttingDown() bool

IsShuttingDown returns true if shutdown is in progress

func (*ShutdownManager) ListenForShutdown added in v0.10.1

func (sm *ShutdownManager) ListenForShutdown()

ListenForShutdown starts listening for shutdown signals

func (*ShutdownManager) RegisterHook added in v0.10.1

func (sm *ShutdownManager) RegisterHook(hook ShutdownHook)

RegisterHook registers a shutdown hook

func (*ShutdownManager) Shutdown added in v0.10.1

func (sm *ShutdownManager) Shutdown() error

Shutdown initiates graceful shutdown

func (*ShutdownManager) ShutdownChan added in v0.10.1

func (sm *ShutdownManager) ShutdownChan() <-chan struct{}

ShutdownChan returns a channel that's closed when shutdown starts

type SimpleLogger added in v0.10.1

type SimpleLogger struct{}

SimpleLogger is a basic logger implementation for when context logger is not available

func (*SimpleLogger) Criticalf added in v0.10.1

func (s *SimpleLogger) Criticalf(format string, args ...interface{})

func (*SimpleLogger) Debugf added in v0.10.1

func (s *SimpleLogger) Debugf(format string, args ...interface{})

func (*SimpleLogger) Errorf added in v0.10.1

func (s *SimpleLogger) Errorf(format string, args ...interface{})

func (*SimpleLogger) Noticef added in v0.10.1

func (s *SimpleLogger) Noticef(format string, args ...interface{})

func (*SimpleLogger) Warningf added in v0.10.1

func (s *SimpleLogger) Warningf(format string, args ...interface{})

type SimpleMetricsRecorder added in v0.10.1

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

SimpleMetricsRecorder provides a basic implementation of JobMetricsRecorder

func NewSimpleMetricsRecorder added in v0.10.1

func NewSimpleMetricsRecorder() *SimpleMetricsRecorder

NewSimpleMetricsRecorder creates a new simple metrics recorder

func (*SimpleMetricsRecorder) GetMetrics added in v0.10.1

func (smr *SimpleMetricsRecorder) GetMetrics() map[string]interface{}

GetMetrics returns all recorded metrics

func (*SimpleMetricsRecorder) RecordJobExecution added in v0.10.1

func (smr *SimpleMetricsRecorder) RecordJobExecution(jobName string, success bool, duration time.Duration)

RecordJobExecution records job execution metrics

func (*SimpleMetricsRecorder) RecordMetric added in v0.10.1

func (smr *SimpleMetricsRecorder) RecordMetric(name string, value interface{})

RecordMetric records a generic metric

func (*SimpleMetricsRecorder) RecordRetryAttempt added in v0.10.1

func (smr *SimpleMetricsRecorder) RecordRetryAttempt(jobName string, attempt int, success bool)

RecordRetryAttempt records retry attempt metrics

type TestContainerMonitor added in v0.10.1

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

Simple test interface to simulate container monitoring

func (*TestContainerMonitor) SetUseEventsAPI added in v0.10.1

func (t *TestContainerMonitor) SetUseEventsAPI(use bool)

func (*TestContainerMonitor) WaitForContainer added in v0.10.1

func (t *TestContainerMonitor) WaitForContainer(containerID string, maxRuntime time.Duration) (*docker.State, error)

type WorkflowExecution added in v0.10.1

type WorkflowExecution struct {
	ID            string
	StartTime     time.Time
	CompletedJobs map[string]bool
	FailedJobs    map[string]bool
	RunningJobs   map[string]bool
	// contains filtered or unexported fields
}

WorkflowExecution tracks the state of a workflow execution

type WorkflowOrchestrator added in v0.10.1

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

WorkflowOrchestrator manages job dependencies and workflow execution

func NewWorkflowOrchestrator added in v0.10.1

func NewWorkflowOrchestrator(scheduler *Scheduler, logger Logger) *WorkflowOrchestrator

NewWorkflowOrchestrator creates a new workflow orchestrator

func (*WorkflowOrchestrator) BuildDependencyGraph added in v0.10.1

func (wo *WorkflowOrchestrator) BuildDependencyGraph(jobs []Job) error

BuildDependencyGraph builds the dependency graph from jobs

func (*WorkflowOrchestrator) CanExecute added in v0.10.1

func (wo *WorkflowOrchestrator) CanExecute(jobName string, executionID string) bool

CanExecute checks if a job can execute based on its dependencies

func (*WorkflowOrchestrator) CleanupOldExecutions added in v0.10.1

func (wo *WorkflowOrchestrator) CleanupOldExecutions(maxAge time.Duration)

CleanupOldExecutions removes old workflow executions

func (*WorkflowOrchestrator) GetWorkflowStatus added in v0.10.1

func (wo *WorkflowOrchestrator) GetWorkflowStatus(executionID string) map[string]interface{}

GetWorkflowStatus returns the status of a workflow execution

func (*WorkflowOrchestrator) JobCompleted added in v0.10.1

func (wo *WorkflowOrchestrator) JobCompleted(jobName string, executionID string, success bool)

JobCompleted marks a job as completed and triggers dependent jobs

func (*WorkflowOrchestrator) JobStarted added in v0.10.1

func (wo *WorkflowOrchestrator) JobStarted(jobName string, executionID string)

JobStarted marks a job as started in the workflow

Jump to

Keyboard shortcuts

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