daemon

package
v1.0.0-beta24 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: Apache-2.0, BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDaemonAlreadyStopped                 = errors.New("daemon was already stopped")
	ErrExistingBackgroundWorkerStillRunning = errors.New("existing background worker is still running")
)

Errors for the daemon package

Functions

func BackgroundWorker

func BackgroundWorker(name string, handler WorkerFunc, priority ...int) error

BackgroundWorker adds a new background worker to the default daemon instance. Use shutdownOrderWorker to define in which shutdown order this particular background worker is shut down (higher = earlier).

func GetRunningBackgroundWorkers

func GetRunningBackgroundWorkers() []string

GetRunningBackgroundWorkers gets the running background workers of the default daemon instance.

func IsRunning

func IsRunning() bool

IsRunning checks whether the default daemon instance is running.

func IsStopped

func IsStopped() bool

IsStopped checks whether the default daemon instance was stopped.

func Run

func Run()

Run runs the default daemon instance and then waits for the daemon to shutdown.

func Shutdown

func Shutdown()

Shutdown signals all background worker of the default daemon instance to shut down. This call doesn't await termination of the background workers.

func ShutdownAndWait

func ShutdownAndWait()

ShutdownAndWait signals all background worker of the default daemon instance to shut down and then waits for their termination.

func Start

func Start()

Start starts the default daemon instance.

Types

type Daemon

type Daemon interface {

	// GetRunningBackgroundWorkers gets the running background workers.
	GetRunningBackgroundWorkers() []string

	// BackgroundWorker adds a new background worker to the daemon.
	// Use order to define in which shutdown order this particular
	// background worker is shut down (higher = earlier).
	BackgroundWorker(name string, handler WorkerFunc, order ...int) error

	// Start starts the daemon.
	Start()

	// Run runs the daemon and then waits for the daemon to shutdown.
	Run()

	// Shutdown signals all background worker of the daemon shut down.
	// This call doesn't await termination of the background workers.
	Shutdown()

	// Shutdown signals all background worker of the daemon to shut down and
	// then waits for their termination.
	ShutdownAndWait()

	// IsRunning checks whether the daemon is running.
	IsRunning() bool

	// IsStopped checks whether the daemon was stopped.
	IsStopped() bool
}

Daemon specifies an interface to run background go routines.

type OrderedDaemon

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

OrderedDaemon is an orchestrator for background workers. stopOnce ensures that the daemon can only be terminated once.

func New

func New() *OrderedDaemon

New creates a new daemon instance.

func (*OrderedDaemon) BackgroundWorker

func (d *OrderedDaemon) BackgroundWorker(name string, handler WorkerFunc, order ...int) error

BackgroundWorker adds a new background worker to the daemon. Use order to define in which shutdown order this particular background worker is shut down (higher = earlier).

func (*OrderedDaemon) GetRunningBackgroundWorkers

func (d *OrderedDaemon) GetRunningBackgroundWorkers() []string

GetRunningBackgroundWorkers gets the running background workers.

func (*OrderedDaemon) IsRunning

func (d *OrderedDaemon) IsRunning() bool

IsRunning checks whether the daemon is running.

func (*OrderedDaemon) IsStopped

func (d *OrderedDaemon) IsStopped() bool

IsStopped checks whether the daemon was stopped.

func (*OrderedDaemon) Run

func (d *OrderedDaemon) Run()

Run runs the daemon and then waits for the daemon to shutdown.

func (*OrderedDaemon) Shutdown

func (d *OrderedDaemon) Shutdown()

Shutdown signals all background worker of the daemon shut down. This call doesn't await termination of the background workers.

func (*OrderedDaemon) ShutdownAndWait

func (d *OrderedDaemon) ShutdownAndWait()

ShutdownAndWait signals all background worker of the daemon to shut down and then waits for their termination.

func (*OrderedDaemon) Start

func (d *OrderedDaemon) Start()

Start starts the daemon.

type WorkerFunc

type WorkerFunc = func(shutdownSignal <-chan struct{})

WorkerFunc is the function to run a worker accepting its shutdown signal handler channel.

Jump to

Keyboard shortcuts

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