lifecycle

package
v1.11.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 4 Imported by: 20

Documentation

Overview

Package lifecycle provides application models' lifecycle management.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongState = errors.New("service is in wrong state")
)

vars

Functions

This section is empty.

Types

type Lifecycle

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

Lifecycle manages lifecycle for models. Currently a Lifecycle has two phases: Start and Stop. Currently Lifecycle doesn't support soft dependency models and multi-err, so all models in Lifecycle require to be succeed on both phases.

func (*Lifecycle) Add

func (lc *Lifecycle) Add(m Model)

Add adds a model into LifeCycle.

func (*Lifecycle) AddModels

func (lc *Lifecycle) AddModels(m ...Model)

AddModels adds multiple models into LifeCycle.

func (*Lifecycle) OnStart

func (lc *Lifecycle) OnStart(ctx context.Context) error

OnStart runs models OnStart function if models implmented it. All OnStart functions will be run in parallel. context passed into models' OnStart method will be canceled on the first time a model's OnStart function return non-nil error.

func (*Lifecycle) OnStartSequentially added in v1.8.0

func (lc *Lifecycle) OnStartSequentially(ctx context.Context) error

OnStartSequentially runs models' Start function if models implmented it.

func (*Lifecycle) OnStop

func (lc *Lifecycle) OnStop(ctx context.Context) error

OnStop runs models Stop function if models implmented it. All OnStop functions will be run in parallel. context passed into models' OnStop method will be canceled on the first time a model's OnStop function return non-nil error.

func (*Lifecycle) OnStopSequentially added in v1.8.0

func (lc *Lifecycle) OnStopSequentially(ctx context.Context) error

OnStopSequentially runs models' Stop function if models implmented it.

type Model

type Model interface{}

Model is application model which may require to start and stop in application lifecycle.

type Readiness added in v1.7.1

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

Readiness is a thread-safe struct to indicate a service's status

func (*Readiness) IsReady added in v1.7.1

func (r *Readiness) IsReady() bool

IsReady returns whether the service is ready (can accept service request)

func (*Readiness) TurnOff added in v1.7.1

func (r *Readiness) TurnOff() error

TurnOff sets the service to not ready (initial state)

func (*Readiness) TurnOn added in v1.7.1

func (r *Readiness) TurnOn() error

TurnOn sets the service to ready (can accept service request)

type StartStopper

type StartStopper interface {
	Starter
	Stopper
}

StartStopper is the interface that groups Start and Stop.

type Starter

type Starter interface {
	// Start runs on lifecycle start phase.
	Start(context.Context) error
}

Starter is Model has a Start method.

type Stopper

type Stopper interface {
	// Stop runs on lifecycle stop phase.
	Stop(context.Context) error
}

Stopper is Model has a Stop method.

Jump to

Keyboard shortcuts

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