Documentation
¶
Overview ¶
Package worker provides a thread pool implementation for concurrent execution of jobs.
Index ¶
- type Config
- type Job
- type JobStatus
- type Pool
- func (p *Pool) ForceKillStuckJobs(threshold time.Duration) int
- func (p *Pool) GetJob(id string) (*Job, bool)
- func (p *Pool) GetStats() Stats
- func (p *Pool) GetStuckJobs(threshold time.Duration) []*Job
- func (p *Pool) IsRateLimited() bool
- func (p *Pool) SetRateLimited(limited bool)
- func (p *Pool) Start()
- func (p *Pool) Stop()
- func (p *Pool) Submit(job *Job) error
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
WorkerCount int // Number of worker goroutines
MaxRetries int // Maximum retry attempts per job
RetryDelay time.Duration // Initial retry delay
MaxRetryDelay time.Duration // Maximum retry delay
BackoffFactor float64 // Exponential backoff multiplier
RateLimitDelay time.Duration // Delay when rate limited
QueueSize int // Size of job queue buffer
LogVerbose bool // Enable verbose logging
}
Config holds configuration for the worker pool
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a sensible default configuration
type Job ¶
type Job struct {
ID string
Description string
Execute func(ctx context.Context) error
Status JobStatus
Attempts int
MaxRetries int
LastError error
CreatedAt time.Time
CompletedAt *time.Time
// contains filtered or unexported fields
}
Job represents a unit of work to be executed
type JobStatus ¶
type JobStatus int
JobStatus represents the current status of a job
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a pool of workers that execute jobs concurrently
func (*Pool) ForceKillStuckJobs ¶
ForceKillStuckJobs attempts to cancel jobs that have been stuck for too long
func (*Pool) GetStuckJobs ¶
GetStuckJobs returns jobs that have been running for longer than the specified duration
func (*Pool) IsRateLimited ¶
IsRateLimited returns true if the pool is currently rate limited
func (*Pool) SetRateLimited ¶
SetRateLimited marks the pool as being rate limited
Click to show internal directories.
Click to hide internal directories.