worker

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package worker manages a set of registered jobs that execute on demand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobFn

type JobFn func(ctx context.Context)

JobFn defines a function that can execute work for a specific job.

type Worker

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

Worker manages jobs and the execution of those jobs concurrently.

func New

func New(maxRunningJobs int) (*Worker, error)

New constructs a Worker for managing and executing jobs. The capacity value represents the maximum number of G's that can be executing at any given time.

func (*Worker) Running

func (w *Worker) Running() int

Running returns the number of jobs running.

func (*Worker) Shutdown

func (w *Worker) Shutdown(ctx context.Context) error

Shutdown waits for all jobs to complete before it returns.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context, jobFn JobFn) (string, error)

Start lookups a job by key and launches a goroutine to perform the work. A work key is returned so the caller can cancel work early.

func (*Worker) Stop

func (w *Worker) Stop(workKey string) error

Stop is used to cancel an existing job that is running.

Jump to

Keyboard shortcuts

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