endure

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 21 Imported by: 30

Documentation

Index

Constants

View Source
const (
	// InitializeMethodName is the method fn to invoke in transition map
	InitializeMethodName = "Initialize"
	// StartMethodName is the method fn to invoke in transition map
	StartMethodName = "Start"
	// ShutdownMethodName is the method fn to invoke in transition map
	ShutdownMethodName = "Shutdown"
)
View Source
const InitMethodName = "Init"

InitMethodName is the function fn for the reflection

View Source
const ServeMethodName = "Serve"

ServeMethodName is the function fn for the Serve

View Source
const StopMethodName = "Stop"

StopMethodName is the function fn for the reflection to Stop the service

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Collects search for the structures or (and) interfaces in the arguments and provides it for the plugin
	Collects() []any
}

Collector declares the ability to accept the plugins which match the provided method signature.

type Container

type Container interface {
	// Serve used to Start the plugin in topological order
	Serve() (<-chan *Result, error)
	// Stop stops the plugins in rev-topological order
	Stop() error
	// Register registers one plugin in container
	Register(service any) error
	// RegisterAll register set of comma separated plugins in container
	RegisterAll(service ...any) error
	// Init initializes all plugins (calling Init function), calculate vertices, invoke Collects and Provided functions if exist
	Init() error
}

Container - Internal container interface

type Endure

type Endure struct {

	// Endure state machine
	fsm.FSM
	// contains filtered or unexported fields
}

Endure struct represent main endure repr

func NewContainer

func NewContainer(logger *zap.Logger, options ...Options) (*Endure, error)

NewContainer returns empty endure container Input parameters: logLevel

-1 is the most informative level - DebugLevel --> also turns on pprof endpoint
0 - InfoLevel defines info log level.
1 -
2 - WarnLevel defines warn log level.
3 - ErrorLevel defines error log level.
4 - FatalLevel defines fatal log level.
5 - PanicLevel defines panic log level.
6 - NoLevel defines an absent log level.
7 - Disabled disables the logger.
see the endure.Level

func (*Endure) Init

func (e *Endure) Init() error

Init container and all service edges.

func (*Endure) Initialize

func (e *Endure) Initialize() error

Initialize used to add edges between vertices, sort graph topologically Do not change this method fn, sync with constants in the beginning of this file

func (*Endure) Register

func (e *Endure) Register(vertex any) error

Register registers the dependencies in the Endure graph without invoking any methods

func (*Endure) RegisterAll

func (e *Endure) RegisterAll(plugins ...any) error

RegisterAll is the helper for the register to register more than one structure in the endure

func (*Endure) Serve

func (e *Endure) Serve() (<-chan *Result, error)

Serve starts serving the graph This is the initial serveInternal, if error produced immediately in the initial serveInternal, endure will traverse deps back, call internal_stop and exit

func (*Endure) Shutdown

func (e *Endure) Shutdown() error

Shutdown used to shutdown the Endure Do not change this method fn, sync with constants in the beginning of this file

func (*Endure) Start

func (e *Endure) Start() (<-chan *Result, error)

Start used to start serving vertices Do not change this method fn, sync with constants in the beginning of this file

func (*Endure) Stop

func (e *Endure) Stop() error

Stop stops the execution and call Stop on every vertex

func (*Endure) Visualize

func (e *Endure) Visualize(vertices []*vertex.Vertex) error

Visualize visualizes the graph based on provided output value

type Level

type Level int8

A Level is a logging priority. Higher levels are more important.

const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel Level = iota - 1
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

type Named

type Named interface {
	// Name return user friendly name of the plugin
	Name() string
}

Named -> Name of the service

type Options

type Options func(endure *Endure)

Options is the endure options

func GracefulShutdownTimeout

func GracefulShutdownTimeout(to time.Duration) Options

GracefulShutdownTimeout sets the timeout to kill the vertices is one or more of them are frozen

func SetBackoff

func SetBackoff(initialInterval time.Duration, maxInterval time.Duration) Options

SetBackoff sets initial and maximum backoff interval for retry

func SetLogLevel

func SetLogLevel(lvl Level) Options

SetLogLevel option sets the log level in the Endure

func Visualize

func Visualize(output Output, path string) Options

Visualize visualize current graph. Output: can be file or stdout

type Output

type Output string

Output represents possible output variants for the visualizer

const (
	// File output type
	File Output = "file"
	// StdOut output type
	StdOut Output = "stdout"
	// Empty is placeholder
	Empty Output = "empty"
)

type Provide

type Provide struct {
	In  []reflect.Type
	Out []reflect.Type
	// contains filtered or unexported fields
}

Provide struct represents a single Provide value, which consists of: 1. m -> method reflected value 2. In -> In types (fn foo(a int, b int)) 3. Out -> returning types (fn boo() a int, b int)

type Provider

type Provider interface {
	// Provides function return set of functions which provided dependencies to other plugins
	Provides() []any
}

Provider declares the ability to provide service edges of declared types.

type Providers

type Providers []Provide

Providers is vertex provides type alias

func (Providers) Len

func (p Providers) Len() int

func (Providers) Less

func (p Providers) Less(i, j int) bool

func (Providers) Swap

func (p Providers) Swap(i, j int)

type Result

type Result struct {
	Error    error
	VertexID string
}

Result is the information which endure sends to the user

type Service

type Service interface {
	// Serve starts the plugin
	Serve() chan error
	// Stop stops the plugin
	Stop() error
}

Service interface can be implemented by the plugin to use Start-Stop functionality

Jump to

Keyboard shortcuts

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