manager

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager keeps track of scheduled goroutines and provides mechanisms to wait for them to finish.

func New

func New(ctx context.Context, opts ...Option) *Manager

New creates a new instance of Manager with the provided generic type for the metadata argument.

func (*Manager) Register

func (m *Manager) Register(task TaskFunc)

Register registers a task to be run by the manager.

func (*Manager) Run

func (m *Manager) Run(task TaskFunc)

Run submits a task to the pool. If all workers are busy, Run will block until a worker is available.

func (*Manager) RunWithRetry

func (m *Manager) RunWithRetry(task TaskFunc, retry *retrier.Retrier)

RunWithRetry runs a task with a dedicated retrier. See [Run] for more details.

func (*Manager) Start

func (m *Manager) Start()

Start starts the manager and runs all the registered tasks.

func (*Manager) Stat

func (m *Manager) Stat() ManagerStats

Stat returns manager statistics.

func (*Manager) Stop

func (m *Manager) Stop() error

Stop cancels the context of the manager and all its tasks.

func (*Manager) Wait

func (m *Manager) Wait() error

Wait blocks until all scheduled tasks have finished and propagate any panics spawned by a child to the caller. Wait returns an error if any of the tasks failed.

type ManagerStats

type ManagerStats struct {
	RunningTasks int `json:"running_tasks"`
}

ManagerStats contains statistics about the tasks operated by the manager.

type Option

type Option func(m *Manager)

func WithCancelOnError

func WithCancelOnError() Option

func WithConstantRetry

func WithConstantRetry(attempts int, backoffDuration time.Duration) Option

func WithExpotentialRetry

func WithExpotentialRetry(attempts int, minBackoffDuration time.Duration, maxBackoffDuration time.Duration) Option

func WithFirstError

func WithFirstError() Option

func WithMaxTasks

func WithMaxTasks(n int) Option

type TaskFunc

type TaskFunc func(ctx context.Context) error

TaskFunc is the function to be executed in a goroutine.

Jump to

Keyboard shortcuts

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