worker

package
v0.0.0-...-0044c33 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: MIT Imports: 4 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 JobFunc

type JobFunc func(ctx context.Context, traceID string, payload interface{})

JobFunc 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(registry map[string]JobFunc) *Worker

New constructs a Worker for managing and executing jobs.

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, traceID string, jobKey string, payload interface{}) (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