Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type DefaultScheduler
- func (s *DefaultScheduler[TIn, TOut]) Shutdown(ctx context.Context) error
- func (s *DefaultScheduler[TIn, TOut]) Stats() SchedulerStats
- func (s *DefaultScheduler[TIn, TOut]) Submit(ctx context.Context, payload TIn, opts ...SubmitOption) (Result[TOut], error)
- func (s *DefaultScheduler[TIn, TOut]) SubmitAsync(ctx context.Context, payload TIn, opts ...SubmitOption) (<-chan Result[TOut], error)
- type DelegateFactory
- type Priority
- type Result
- type Scheduler
- type SchedulerStats
- type SubmitOption
- type Task
- type Worker
- type WorkerDelegate
- type WorkerPool
Constants ¶
Variables ¶
View Source
var ( ErrQueueFull = errors.New("taskpool: queue is full") ErrWorkerStopped = errors.New("taskpool: worker is stopped") ErrPoolShutdown = errors.New("taskpool: pool is shutdown") ErrInvalidPriority = errors.New("taskpool: invalid priority") ErrInvalidConfig = errors.New("taskpool: invalid configuration") ErrDelegateInitFailed = errors.New("taskpool: delegate initialization failed") ErrMaxWorkersReached = errors.New("taskpool: max workers reached") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[TIn, TOut any] struct { MinWorkers int MaxWorkers int // 0 = runtime.NumCPU() * 2 IdleTimeout time.Duration // Workers stop if idle longer than this TaskQueueSize int TaskTimeout time.Duration MaxTaskTimeout time.Duration DelegateFactory DelegateFactory[TIn, TOut] DelegateConfig any HealthCheckInterval time.Duration Logger log.Logger }
type DefaultScheduler ¶
type DefaultScheduler[TIn, TOut any] struct { // contains filtered or unexported fields }
func (*DefaultScheduler[TIn, TOut]) Shutdown ¶
func (s *DefaultScheduler[TIn, TOut]) Shutdown(ctx context.Context) error
func (*DefaultScheduler[TIn, TOut]) Stats ¶
func (s *DefaultScheduler[TIn, TOut]) Stats() SchedulerStats
func (*DefaultScheduler[TIn, TOut]) Submit ¶
func (s *DefaultScheduler[TIn, TOut]) Submit(ctx context.Context, payload TIn, opts ...SubmitOption) (Result[TOut], error)
func (*DefaultScheduler[TIn, TOut]) SubmitAsync ¶
func (s *DefaultScheduler[TIn, TOut]) SubmitAsync(ctx context.Context, payload TIn, opts ...SubmitOption) (<-chan Result[TOut], error)
type DelegateFactory ¶
type DelegateFactory[TIn, TOut any] func() WorkerDelegate[TIn, TOut]
type Scheduler ¶
type Scheduler[TIn, TOut any] interface { // Submit blocks until task completes or context is canceled. Submit(ctx context.Context, payload TIn, opts ...SubmitOption) (Result[TOut], error) // SubmitAsync returns immediately with a result channel. SubmitAsync(ctx context.Context, payload TIn, opts ...SubmitOption) (<-chan Result[TOut], error) Stats() SchedulerStats // Shutdown waits for running tasks to complete. Shutdown(ctx context.Context) error }
Scheduler manages task submission and execution.
type SchedulerStats ¶
type SubmitOption ¶
type SubmitOption func(*submitOptions)
func WithPriority ¶
func WithPriority(p Priority) SubmitOption
type Task ¶
type Task[TIn, TOut any] struct { Id string Context context.Context Priority Priority Payload TIn Result chan<- Result[TOut] Done chan struct{} // Closed by worker after execution SubmittedAt time.Time }
Task is a unit of work executed by a worker.
type Worker ¶
type Worker[TIn, TOut any] struct { // contains filtered or unexported fields }
Worker executes tasks in a dedicated OS thread.
type WorkerDelegate ¶
type WorkerDelegate[TIn, TOut any] interface { // Init is called once when worker starts. Init(ctx context.Context, config any) error // Execute runs for each task. Must respect context cancellation. Execute(ctx context.Context, payload TIn) (TOut, error) // Destroy is called once when worker stops. Destroy() error // HealthCheck is called periodically. HealthCheck() error }
WorkerDelegate defines pluggable task execution logic. Each worker owns its delegate instance, all methods run in worker's OS thread.
type WorkerPool ¶
type WorkerPool[TIn, TOut any] struct { // contains filtered or unexported fields }
WorkerPool manages elastic worker scaling with priority queues.
Click to show internal directories.
Click to hide internal directories.