workers

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package workers provides a worker pool implementation for concurrent operations in scanorama. It supports job queuing, rate limiting, graceful shutdown, and integrates with the structured logging and metrics systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Size is the number of worker goroutines to create.
	Size int
	// QueueSize is the maximum number of jobs that can be queued.
	QueueSize int
	// MaxRetries is the maximum number of retries for failed jobs.
	MaxRetries int
	// RetryDelay is the delay between retries.
	RetryDelay time.Duration
	// ShutdownTimeout is the maximum time to wait for workers to finish.
	ShutdownTimeout time.Duration
	// RateLimit is the maximum number of jobs per second (0 = no limit).
	RateLimit int
}

Config holds configuration for the worker pool.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default worker pool configuration.

type DiscoveryJob

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

DiscoveryJob implements Job interface for discovery operations.

func NewDiscoveryJob

func NewDiscoveryJob(id, network, method string,
	executor func(ctx context.Context, network, method string) error) *DiscoveryJob

NewDiscoveryJob creates a new discovery job.

func (*DiscoveryJob) Execute

func (j *DiscoveryJob) Execute(ctx context.Context) error

Execute implements the Job interface.

func (*DiscoveryJob) ID

func (j *DiscoveryJob) ID() string

ID implements the Job interface.

func (*DiscoveryJob) Type

func (j *DiscoveryJob) Type() string

Type implements the Job interface.

type Job

type Job interface {
	// Execute performs the job and returns an error if it fails.
	Execute(ctx context.Context) error
	// ID returns a unique identifier for the job.
	ID() string
	// Type returns the job type for metrics and logging.
	Type() string
}

Job represents a unit of work to be executed by a worker.

type Pool

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

Pool manages a pool of worker goroutines for concurrent job execution.

func New

func New(config Config) *Pool

New creates a new worker pool with the given configuration.

func (*Pool) Results

func (p *Pool) Results() <-chan Result

Results returns a channel for receiving job results.

func (*Pool) Shutdown

func (p *Pool) Shutdown() error

Shutdown gracefully shuts down the worker pool.

func (*Pool) Start

func (p *Pool) Start()

Start begins the worker pool operations.

func (*Pool) Submit

func (p *Pool) Submit(job Job) error

Submit adds a job to the worker pool queue.

func (*Pool) Wait

func (p *Pool) Wait()

Wait waits for all workers to complete and the pool to shut down.

type Result

type Result struct {
	JobID    string
	JobType  string
	Error    error
	Duration time.Duration
	Retries  int
}

Result represents the result of executing a job.

type ScanJob

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

ScanJob implements Job interface for scan operations.

func NewScanJob

func NewScanJob(id, target, ports, scanType string,
	executor func(ctx context.Context, target, ports, scanType string) error) *ScanJob

NewScanJob creates a new scan job.

func (*ScanJob) Execute

func (j *ScanJob) Execute(ctx context.Context) error

Execute implements the Job interface.

func (*ScanJob) ID

func (j *ScanJob) ID() string

ID implements the Job interface.

func (*ScanJob) Type

func (j *ScanJob) Type() string

Type implements the Job interface.

Jump to

Keyboard shortcuts

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