Documentation ¶
Index ¶
- Variables
- func BackgroundWorker(name string, handler WorkerFunc, priority ...int) error
- func ContextStopped() context.Context
- func DebugLogger(logger log.Logger)
- func GetRunningBackgroundWorkers() []string
- func IsRunning() bool
- func IsStopped() bool
- func Run()
- func Shutdown()
- func ShutdownAndWait()
- func Start()
- type Daemon
- type OrderedDaemon
- func (d *OrderedDaemon) BackgroundWorker(name string, handler WorkerFunc, order ...int) error
- func (d *OrderedDaemon) ContextStopped() context.Context
- func (d *OrderedDaemon) DebugLogger(logger log.Logger)
- func (d *OrderedDaemon) GetRunningBackgroundWorkers() []string
- func (d *OrderedDaemon) IsRunning() bool
- func (d *OrderedDaemon) IsStopped() bool
- func (d *OrderedDaemon) Run()
- func (d *OrderedDaemon) Shutdown()
- func (d *OrderedDaemon) ShutdownAndWait()
- func (d *OrderedDaemon) Start()
- type WorkerFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrDaemonAlreadyStopped = ierrors.New("daemon was already stopped") ErrDuplicateBackgroundWorker = ierrors.New("duplicate background worker") ErrExistingBackgroundWorkerStillRunning = ierrors.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 ContextStopped ¶
ContextStopped returns a context that is done when the deamon is stopped.
func DebugLogger ¶
DebugLogger allows to pass a logger to the daemon to issue log messages for debugging purposes.
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.
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 // DebugLogger allows to pass a logger to the daemon to issue log messages for debugging purposes. DebugLogger(logger log.Logger) // 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 // ContextStopped returns a context that is done when the deamon is stopped. ContextStopped() context.Context }
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 (*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) ContextStopped ¶
func (d *OrderedDaemon) ContextStopped() context.Context
ContextStopped returns a context that is done when the deamon is stopped.
func (*OrderedDaemon) DebugLogger ¶
func (d *OrderedDaemon) DebugLogger(logger log.Logger)
DebugLogger allows to pass a logger to the daemon to issue log messages for debugging purposes.
func (*OrderedDaemon) GetRunningBackgroundWorkers ¶
func (d *OrderedDaemon) GetRunningBackgroundWorkers() []string
GetRunningBackgroundWorkers gets the running background workers sorted by their priority.
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.
type WorkerFunc ¶
WorkerFunc is the function to run a worker accepting its context.