Documentation ¶
Overview ¶
Package service provides ready-to-use primitives for creating services in Acronis Cyber Cloud.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPeriodicWorkerStop = errors.New("stop periodic worker error")
ErrPeriodicWorkerStop is an error that may be used for interrupting PeriodicWorker's loop.
var ErrWorkerUnitStopTimeoutExceeded = errors.New("worker unit stop timeout exceeded")
ErrWorkerUnitStopTimeoutExceeded is an error that occurs when WorkerUnit's gracefully stop timeout is exceeded.
Functions ¶
This section is empty.
Types ¶
type CompositeUnit ¶
type CompositeUnit struct {
Units []Unit
}
CompositeUnit represents a composition of service units and implements Composite design pattern.
func NewCompositeUnit ¶
func NewCompositeUnit(units ...Unit) *CompositeUnit
NewCompositeUnit creates a new composite unit.
func (*CompositeUnit) MustRegisterMetrics ¶
func (cu *CompositeUnit) MustRegisterMetrics()
MustRegisterMetrics registers metrics in Prometheus client and panics if any error occurs.
func (*CompositeUnit) Start ¶
func (cu *CompositeUnit) Start(fatalError chan<- error)
Start starts all units in the composition (each in its own separate goroutine) and blocks. If fatal error occurs in any unit, it tries to stop (not gracefully) other ones and sends CompositeUnitError (may contain errors caused by stopping too) to passed channel.
func (*CompositeUnit) Stop ¶
func (cu *CompositeUnit) Stop(gracefully bool) error
Stop stops all units in the composition (each in its own separate goroutine). Errors that occurred while stopping the units are collected and single CompositeUnitError is returned.
func (*CompositeUnit) UnregisterMetrics ¶
func (cu *CompositeUnit) UnregisterMetrics()
UnregisterMetrics unregisters metrics in Prometheus client.
type CompositeUnitError ¶
type CompositeUnitError struct {
UnitErrors []error
}
CompositeUnitError is an error which may occurs in CompositeUnit's methods.
func (*CompositeUnitError) Error ¶
func (cue *CompositeUnitError) Error() string
Error returns a string representation of a units composition error.
type MetricsRegisterer ¶
type MetricsRegisterer interface { MustRegisterMetrics() UnregisterMetrics() }
MetricsRegisterer is an interface for objects that can register its own metrics.
type PeriodicWorker ¶
type PeriodicWorker struct {
// contains filtered or unexported fields
}
PeriodicWorker represents a worker that runs underlying worker periodically.
func NewPeriodicWorker ¶
func NewPeriodicWorker(worker Worker, intervalDelay time.Duration, logger log.FieldLogger) *PeriodicWorker
NewPeriodicWorker creates a new instance of PeriodicWorker with constant delays.
func NewPeriodicWorkerWithOpts ¶
func NewPeriodicWorkerWithOpts( worker Worker, intervalDelay time.Duration, logger log.FieldLogger, opts PeriodicWorkerOpts, ) *PeriodicWorker
NewPeriodicWorkerWithOpts creates a new instance of PeriodicWorker with an ability to specify different optional parameters.
type PeriodicWorkerOpts ¶
type PeriodicWorkerOpts struct { InitialDelay time.Duration IntervalDelayFunc func(worker Worker, err error) time.Duration }
PeriodicWorkerOpts contains optional parameters for constructing PeriodicWorker.
type Service ¶
Service represents a service which can register metrics in Prometheus client, start unit and stop it in a graceful way by OS signal.
func New ¶
func New(logger log.FieldLogger, unit Unit) *Service
New creates new Service which will start and stop passing unit.
func NewWithOpts ¶
func NewWithOpts(logger log.FieldLogger, unit Unit, opts Opts) *Service
NewWithOpts is a more configurable version of New.
type Unit ¶
Unit is a common interface for all service units. Unit is a single component in service with its own life-cycle.
type WorkerFunc ¶
WorkerFunc is an adapter to allow the use of ordinary functions as Worker.
type WorkerUnit ¶
type WorkerUnit struct {
// contains filtered or unexported fields
}
WorkerUnit allows presenting Worker as Unit.
func NewWorkerUnit ¶
func NewWorkerUnit(worker Worker) *WorkerUnit
NewWorkerUnit creates a new instance of WorkerUnit.
func NewWorkerUnitWithOpts ¶
func NewWorkerUnitWithOpts(worker Worker, opts WorkerUnitOpts) *WorkerUnit
NewWorkerUnitWithOpts creates a new instance of WorkerUnit with an ability to specify different optional parameters.
func (*WorkerUnit) MustRegisterMetrics ¶
func (u *WorkerUnit) MustRegisterMetrics()
MustRegisterMetrics registers underlying Worker's metrics.
func (*WorkerUnit) Start ¶
func (u *WorkerUnit) Start(fatalError chan<- error)
Start starts (call Run() method) underlying Worker.
func (*WorkerUnit) Stop ¶
func (u *WorkerUnit) Stop(gracefully bool) error
Stop stops underlying Worker.
func (*WorkerUnit) UnregisterMetrics ¶
func (u *WorkerUnit) UnregisterMetrics()
UnregisterMetrics unregisters underlying Worker's metrics.
type WorkerUnitOpts ¶
type WorkerUnitOpts struct { MetricsRegisterer MetricsRegisterer GracefulStopTimeout time.Duration }
WorkerUnitOpts contains optional parameters for constructing PeriodicWorker.