Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDaemonClosed = errors.New("dsps.daemon.closed")
ErrDaemonClosed means daemon has been shutdown
var ErrLockCanceled error = &errLockCanceled{}
ErrLockCanceled is for error.Is() type checking.
Functions ¶
This section is empty.
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon represents a running daemon
func (*Daemon) RequestShutdown ¶
func (d *Daemon) RequestShutdown()
RequestShutdown ask this daemon to stop. Not wait until shutdown.
func (*Daemon) WaitNextCycle ¶
WaitNextCycle block until this daemon runs at least once since now. Callback f() is called while waiting cycle, useful to prevent missfire. Returns DaemonClosed if daemon has been shutdown.
type DaemonErrorHandler ¶
DaemonErrorHandler catch error of daemons
type DaemonFunc ¶
type DaemonFunc func(context.Context) (DaemonNextRun, error)
DaemonFunc is user-defined implementation of the daemon. Note: this function must return valid DaemonNextRun struct even if error occurs.
type DaemonNextRun ¶
DaemonNextRun controls next daemon execution
type DaemonSystem ¶
type DaemonSystem struct {
// contains filtered or unexported fields
}
DaemonSystem represents controller of daemons
func NewDaemonSystem ¶
func NewDaemonSystem(name string, deps DaemonSystemDeps, errorHandler DaemonErrorHandler) *DaemonSystem
NewDaemonSystem create new runtime for daemons
func (*DaemonSystem) Get ¶
func (ds *DaemonSystem) Get(name string) *Daemon
Get returns Daemon instance in this system.
func (*DaemonSystem) Shutdown ¶
func (ds *DaemonSystem) Shutdown(ctx context.Context) error
Shutdown closes this system, block until all daemons end.
func (*DaemonSystem) Start ¶
func (ds *DaemonSystem) Start(name string, f DaemonFunc) *Daemon
Start creates new Daemon instance. "name" parameter must be unique in the DaemonSystem.
func (*DaemonSystem) String ¶
func (ds *DaemonSystem) String() string
type DaemonSystemDeps ¶
DaemonSystemDeps is dependencies of daemon system.