sync

package
v0.0.0-...-ef901e4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDaemonClosed = errors.New("dsps.daemon.closed")

ErrDaemonClosed means daemon has been shutdown

View Source
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) String

func (d *Daemon) String() string

func (*Daemon) WaitNextCycle

func (d *Daemon) WaitNextCycle(ctx context.Context, f func()) error

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.

func (*Daemon) WaitUntilShutdown

func (d *Daemon) WaitUntilShutdown(ctx context.Context) error

WaitUntilShutdown blocks until this daemon ends.

type DaemonErrorHandler

type DaemonErrorHandler func(ctx context.Context, name string, err error)

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

type DaemonNextRun struct {
	Interval time.Duration
	Abort    bool // true to terminate this daemon
}

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

type DaemonSystemDeps struct {
	Telemetry *telemetry.Telemetry
	Sentry    sentry.Sentry
}

DaemonSystemDeps is dependencies of daemon system.

type Lock

type Lock interface {
	Lock(ctx context.Context) (UnlockFunc, error)
}

Lock is an interface of context-aware lock system.

func NewLock

func NewLock() Lock

NewLock creates Lock instance.

type UnlockFunc

type UnlockFunc func()

UnlockFunc is an func() that unlock acquired lock.

Jump to

Keyboard shortcuts

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