dispatcher

package
v0.0.0-...-88db892 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	GetName() string
	Run(ctx context.Context) error

	Shutdown() <-chan struct{}
	// contains filtered or unexported methods
}

Dispatcher ...

type Job

type Job interface {
	GetJobID() string
	DoJob() []error
}

Job ...

type JobConsumer

type JobConsumer interface {
	Consume() Job
}

JobConsumer ...

type LocalDispatcher

type LocalDispatcher struct {
	Name       string
	WorkerPool chan chan Job
	MaxWorkers int
	JobQueue   chan Job
	// contains filtered or unexported fields
}

LocalDispatcher - Go channel based job dispatcher for managed job handling where the jobs will be produced and consumed within the instance

func NewLocalDispatcher

func NewLocalDispatcher(name string, maxWorkers int, jobQueue chan Job) (*LocalDispatcher, error)

NewLocalDispatcher - Dispaches the configures number of workers based on the jobs available from the provided Go Channel (JobQueue) Jobs should be produced to the assigned go channel (JobQueue)

func (*LocalDispatcher) GetName

func (d *LocalDispatcher) GetName() string

GetName - Gets the name of the dispatcher

func (*LocalDispatcher) Run

func (d *LocalDispatcher) Run(ctx context.Context) (err error)

Run - Dispatches the workers as per the configuration

func (*LocalDispatcher) Shutdown

func (d *LocalDispatcher) Shutdown() <-chan struct{}

Shutdown - Gracefully shuts down the dispatcher by closing the job enqueuing channel and waits for workers to complete the accepted jobs

type Worker

type Worker struct {
	WorkerID   string
	WorkerPool chan chan Job
	JobChannel chan Job
	// contains filtered or unexported fields
}

Worker represents the worker that executes the job

func NewWorker

func NewWorker(workerID string, workerPool chan chan Job) (*Worker, error)

NewWorker ...

func (*Worker) Start

func (w *Worker) Start(ctx context.Context)

Start method starts the run loop for the worker, listening for a quit channel in case we need to stop it

func (*Worker) Stop

func (w *Worker) Stop()

Stop signals the worker to stop listening for work requests.

Jump to

Keyboard shortcuts

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