worker

package
v0.0.78 Latest Latest
Warning

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

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

Documentation

Overview

Package worker provides a generic worker pool for processing queued jobs. This package offers concurrent job processing with configurable worker counts per queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Queues map[string]int // Queue name -> number of workers
}

Config configures the worker pool

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default worker configuration

type JobProcessor

type JobProcessor interface {
	Process(ctx context.Context, job interface{}) error
	GetJobID(job interface{}) string
	GetTimeout(job interface{}) time.Duration
}

JobProcessor defines the interface for processing jobs

type Pool

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

Pool manages a pool of workers that process jobs from queues

func NewPool

func NewPool(queue Queue, processor JobProcessor, config Config) *Pool

NewPool creates a new worker pool

func (*Pool) Start

func (p *Pool) Start()

Start starts all workers in the pool

func (*Pool) Stop

func (p *Pool) Stop()

Stop stops all workers in the pool

type Queue

type Queue interface {
	Dequeue(queueName string, timeout time.Duration) (interface{}, error)
	Enqueue(job interface{}) error
	MarkProcessing(jobID string, deadline time.Time) error
	CompleteJob(jobID string) error
	FailJob(jobID string, requeue bool, queueName string, retryCount int) error
}

Queue defines the interface for job queue operations

type Worker

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

Worker represents a single worker that processes jobs from a queue

func (*Worker) Start

func (w *Worker) Start()

Start starts a worker processing loop

Jump to

Keyboard shortcuts

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