worker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// FileImportWorkers defines the number of concurrent workers for file import jobs
	FileImportWorkers uint
	// ThumbnailWorkers defines the number of concurrent workers for thumbnail generation jobs
	ThumbnailWorkers uint
	// FileDeletionWorkers defines the number of concurrent workers for file deletion jobs
	FileDeletionWorkers uint
	// ChannelBufferSize defines the buffer size for job channels
	// A larger buffer allows more jobs to be queued in memory before blocking
	ChannelBufferSize uint
}

Config holds the configuration for the worker system

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default worker configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type Manager

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

Manager orchestrates all worker pools and job distribution

func NewManager

func NewManager(config Config) (*Manager, error)

NewManager creates a new worker manager with the given configuration

func (*Manager) EnqueueFileDeletion

func (m *Manager) EnqueueFileDeletion(job *job.FileDeletionJob) error

EnqueueFileDeletion submits a file deletion job to the worker pool

func (*Manager) EnqueueFileImport

func (m *Manager) EnqueueFileImport(job *job.FileImportJob) error

EnqueueFileImport submits a file import job to the worker pool

func (*Manager) EnqueueThumbnail

func (m *Manager) EnqueueThumbnail(job *job.ThumbnailJob) error

EnqueueThumbnail submits a thumbnail job to the worker pool

func (*Manager) RecoverPendingJobs

func (m *Manager) RecoverPendingJobs() error

RecoverPendingJobs loads pending jobs from the database and submits them to workers This should be called once at application startup, after Start()

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown performs a graceful shutdown of all worker pools It stops accepting new jobs and waits for current jobs to complete

func (*Manager) Start

func (m *Manager) Start() error

Start launches all worker pools

type Pool

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

Pool represents a pool of workers processing jobs from a channel

func NewPool

func NewPool(name string, workerCount uint, bufferSize uint) *Pool

NewPool creates a new worker pool

func (*Pool) Close

func (p *Pool) Close()

Close closes the job channel No more jobs can be submitted after this

func (*Pool) Start

func (p *Pool) Start(ctx context.Context)

Start launches all workers in the pool Workers will run until the context is cancelled

func (*Pool) Submit

func (p *Pool) Submit(ctx context.Context, job job.Job) error

Submit adds a job to the pool's queue This call may BLOCK if the channel buffer is full (default: 100 jobs) and all workers are busy processing. It will unblock once a worker finishes a job and frees space in the queue. Returns an error if the context is cancelled while waiting

func (*Pool) Wait

func (p *Pool) Wait()

Wait blocks until all workers have finished processing Should be called after the context is cancelled

Jump to

Keyboard shortcuts

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