background_worker

package
v0.0.0-...-7edcfce Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ContextUser string = "background_user"
View Source
const DefaultTimeout = 10 * time.Second

Variables

View Source
var DefaultSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM}

Functions

This section is empty.

Types

type BackgroundStopper

type BackgroundStopper interface {
	IsStopped() bool
}

type BackgroundStopperStub

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

func (*BackgroundStopperStub) IsStopped

func (b *BackgroundStopperStub) IsStopped() bool

func (*BackgroundStopperStub) Stop

func (b *BackgroundStopperStub) Stop()

type BackgroundWorker

type BackgroundWorker struct {
	logger.WithLoggerBase

	Period int
	Name   string

	CondChan *condchan.CondChan
	Finished chan bool
	Stopped  atomic.Bool
	Running  atomic.Bool

	JobRunner JobRunner
}

func New

func New(log logger.Logger, jobRunner JobRunner, period int, name ...string) *BackgroundWorker

func (*BackgroundWorker) IsStopped

func (w *BackgroundWorker) IsStopped() bool

func (*BackgroundWorker) Run

func (w *BackgroundWorker) Run(fin Finisher)

func (*BackgroundWorker) RunInBackground

func (w *BackgroundWorker) RunInBackground()

func (*BackgroundWorker) Shutdown

func (w *BackgroundWorker) Shutdown(ctx system_context.Context) error

func (*BackgroundWorker) Stop

func (w *BackgroundWorker) Stop()

type Finisher

type Finisher interface {
	AddRunner(runner Runner, config ...*RunnerConfig)
	Wait()
	Shutdown(ctx context.Context) error
	RemoveRunner(name string)
}

type FinisherBase

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

func NewFinisher

func NewFinisher(config ...*FinisherConfig) *FinisherBase

func (*FinisherBase) AddRunner

func (f *FinisherBase) AddRunner(runner Runner, config ...*RunnerConfig)

func (*FinisherBase) RemoveRunner

func (f *FinisherBase) RemoveRunner(name string)

func (*FinisherBase) Shutdown

func (f *FinisherBase) Shutdown(ctx context.Context) error

func (*FinisherBase) Wait

func (f *FinisherBase) Wait()

type FinisherConfig

type FinisherConfig struct {
	FinisherMainConfig

	// Log can be set to change where finish logs to.
	Logger logger.Logger
}

type FinisherMainConfig

type FinisherMainConfig struct {

	// Timeout is the maximum amount of time to wait for
	// still running runners requests to finish,
	// when the shutdown signal was received for each runner.
	//
	// It defaults to DefaultTimeout which is 10 seconds.
	//
	// The timeout can be overridden on a per-server basis with passing the
	// WithTimeout() option to Add() while adding the runner.
	Timeout time.Duration

	// Signals can be used to change which signals finish catches to initiate
	// the shutdown.
	// It defaults to DefaultSignals which contains SIGINT and SIGTERM.
	Signals []os.Signal
}

type JobRunner

type JobRunner interface {
	RunJob()
	StopJob()
	SetStopper(stopper BackgroundStopper)
	Stopper() BackgroundStopper
}

type JobRunnerBase

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

func (*JobRunnerBase) SetStopper

func (j *JobRunnerBase) SetStopper(stopper BackgroundStopper)

func (*JobRunnerBase) StopJob

func (j *JobRunnerBase) StopJob()

func (*JobRunnerBase) Stopper

func (j *JobRunnerBase) Stopper() BackgroundStopper

type Runner

type Runner interface {
	Shutdown(ctx context.Context) error
}

type RunnerConfig

type RunnerConfig struct {
	Name    optional.String
	Timeout optional.Int
}

type WithBackgroundWorker

type WithBackgroundWorker interface {
	Worker() *BackgroundWorker
}

type WithBackgroundWorkerBase

type WithBackgroundWorkerBase struct {
	WorkerInterface *BackgroundWorker
}

func (*WithBackgroundWorkerBase) Worker

Jump to

Keyboard shortcuts

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