worker

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.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 Func

type Func func(ctx context.Context) error

Func defines the signature for a unit of work to be executed.

type Runner

type Runner struct {
	Works []Work // Works holds the list of work items to be executed.
	// contains filtered or unexported fields
}

Runner manages and executes a set of Work items.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run starts all configured Work items in the Runner. It returns an error if the Runner is already running. Each Work item is set up and scheduled in its own goroutine.

func (*Runner) Stop

func (r *Runner) Stop(ctx context.Context) error

Stop halts all running Work items managed by the Runner. It cancels the context for all workers and closes their work channels. Returns an error if the Runner is not running.

type Work

type Work struct {
	Name         string        // Name identifies the work item.
	Fn           Func          // Fn is the function to execute.
	NoOfWorkers  int           // NoOfWorkers specifies the number of concurrent workers for this work item.
	ExecInterval time.Duration // ExecInterval is the interval between executions of the work function.
	Timeout      time.Duration // Timeout is the maximum duration allowed for the work function to complete.
}

Work defines a unit of work to be executed by the Runner.

Jump to

Keyboard shortcuts

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