services

package
v0.0.0-...-ae8e89f Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Daemonize

func Daemonize(manager SystemManager, f DaemonFunction, name string)

func GracefulShutdown

func GracefulShutdown(ctx context.Context, killFunc func())

GracefulShutdown sets up a shutdown handler that calls killFunc when the process needs to clean up and terminate. killFunc will be executed at most once.

Types

type DaemonFunction

type DaemonFunction func(ctx context.Context) (ShutdownFunction, chan error)

type ManagerOption

type ManagerOption func(*managerOpts)

ManagerOption allows the manager to be customized via options.

func WithContext

func WithContext(ctx context.Context) ManagerOption

WithContext allows to set root context instead of using context.Background() by default

func WithLogSampling

func WithLogSampling(sampling *zap.SamplingConfig) ManagerOption

WithLogSampling will enable sampling on the default logger if you didn't provide one yourself. This option will have no effect if used with the WithLogger option.

func WithLogger

func WithLogger(logger *zap.Logger) ManagerOption

WithLogger allows the logger to be injected into the manager.

type MockSystemManager

type MockSystemManager struct {
	GContext          context.Context
	GLogger           *zap.Logger
	GTracer           opentracing.Tracer
	GServiceContext   context.Context
	GServiceWaitGroup *sync.WaitGroup
	GShutdownHooks    []ShutdownHook
	GPreShutdownHooks []PreShutdownHook
}

func (*MockSystemManager) AddPreShutdownHook

func (m *MockSystemManager) AddPreShutdownHook(hook PreShutdownHook)

func (*MockSystemManager) AddShutdownHook

func (m *MockSystemManager) AddShutdownHook(hook ShutdownHook)

func (*MockSystemManager) Context

func (m *MockSystemManager) Context() context.Context

func (*MockSystemManager) Logger

func (m *MockSystemManager) Logger() *zap.Logger

func (*MockSystemManager) ServiceContext

func (m *MockSystemManager) ServiceContext() context.Context

func (*MockSystemManager) ServiceWaitGroup

func (m *MockSystemManager) ServiceWaitGroup() *sync.WaitGroup

func (*MockSystemManager) Shutdown

func (m *MockSystemManager) Shutdown()

func (*MockSystemManager) State

func (m *MockSystemManager) State() ServiceState

func (*MockSystemManager) Tracer

func (m *MockSystemManager) Tracer() opentracing.Tracer

func (*MockSystemManager) WaitForInterrupt

func (m *MockSystemManager) WaitForInterrupt()

type Params

type Params struct {
	fx.In
	SystemManager SystemManager `optional:"true"`
}

type PreShutdownHook

type PreShutdownHook func()

type ServiceState

type ServiceState int
const (
	Starting ServiceState = iota + 1
	Running
	Stopping
	Terminated
	Failed
)

type ShutdownFunction

type ShutdownFunction func(ctx context.Context) error

type ShutdownHook

type ShutdownHook func()

type SystemManager

type SystemManager interface {
	Context() context.Context
	Logger() *zap.Logger
	Tracer() opentracing.Tracer
	ServiceContext() context.Context
	ServiceWaitGroup() *sync.WaitGroup
	State() ServiceState
	AddPreShutdownHook(PreShutdownHook)
	AddShutdownHook(ShutdownHook)
	WaitForInterrupt()
	Shutdown()
}

func NewManager

func NewManager(opts ...ManagerOption) SystemManager

NewManager creates a new system manager.

func NewMockSystemManager

func NewMockSystemManager() SystemManager

Jump to

Keyboard shortcuts

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