bda

package module
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

Biological Driven Architecture

biological-driven-architecture

Documentation

Index

Constants

View Source
const (
	LogOperationInit        LogOperation = "init"
	LogOperationRun         LogOperation = "run"
	LogOperationStop        LogOperation = "stop"
	LogOperationHandleError LogOperation = "handle-error"

	LogStatusStart    LogStatus = "start"
	LogStatusProgress LogStatus = "progress"
	LogStatusSuccess  LogStatus = "success"
	LogStatusFailed   LogStatus = "failed"
)

Variables

This section is empty.

Functions

func LogDebug added in v0.1.1

func LogDebug(runtime Runtime, operation LogOperation, status LogStatus)

func LogDebugf added in v0.1.1

func LogDebugf(runtime Runtime, operation LogOperation, status LogStatus, format string, args ...interface{})

func LogError added in v0.1.1

func LogError(runtime Runtime, operation LogOperation, status LogStatus)

func LogErrorf added in v0.1.1

func LogErrorf(runtime Runtime, operation LogOperation, status LogStatus, format string, args ...interface{})

func LogFatal added in v0.1.1

func LogFatal(runtime Runtime, operation LogOperation, status LogStatus)

func LogFatalf added in v0.1.1

func LogFatalf(runtime Runtime, operation LogOperation, status LogStatus, format string, args ...interface{})

func LogInfo added in v0.1.1

func LogInfo(runtime Runtime, operation LogOperation, status LogStatus)

func LogInfof added in v0.1.1

func LogInfof(runtime Runtime, operation LogOperation, status LogStatus, format string, args ...interface{})

func LogPanic added in v0.1.1

func LogPanic(runtime Runtime, operation LogOperation, status LogStatus)

func LogPanicf added in v0.1.1

func LogPanicf(runtime Runtime, operation LogOperation, status LogStatus, format string, args ...interface{})

func LogWarn added in v0.1.1

func LogWarn(runtime Runtime, operation LogOperation, status LogStatus)

func LogWarnf added in v0.1.1

func LogWarnf(runtime Runtime, operation LogOperation, status LogStatus, format string, args ...interface{})

func WorkerPoolStrategyRunLoop added in v0.1.1

func WorkerPoolStrategyRunLoop(p *WorkerPool, i int, wg *sync.WaitGroup, errs SafeArray[Error])

func WorkerPoolStrategyRunOnce added in v0.1.1

func WorkerPoolStrategyRunOnce(p *WorkerPool, i int, wg *sync.WaitGroup, errs SafeArray[Error])

Types

type Builder

type Builder[T any] interface {
	Spawn(name string, ctx context.Context) (T, Error)
}

type Error

type Error *ErrorStruct

func HandleErrors added in v0.1.24

func HandleErrors(runtime Runtime, logOperation LogOperation, errs SafeArray[Error]) Error

func NewError

func NewError(errorType ErrorType, msg string, subErrors []Error) Error

type ErrorSeverity added in v0.1.1

type ErrorSeverity int
const (
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel ErrorSeverity = iota
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel
)

type ErrorStruct

type ErrorStruct struct {
	Type      ErrorType
	Severity  ErrorSeverity
	Message   string
	SubErrors []Error
}

type ErrorType

type ErrorType string

type Leaser added in v0.1.23

type Leaser interface {
	GetLease(id string) (time.Time, error)
	ResetLease(id string, allegedLeaseTime time.Time) (time.Time, error)
}

Leaser interface provides methods to get and reset lease time for an ID.

type LeaserBuilder added in v0.1.23

type LeaserBuilder interface {
	Build() Leaser
}

LeaserBuilder interface provides a method to build a Leaser instance.

func NewInMemoryLeaserBuilder added in v0.1.23

func NewInMemoryLeaserBuilder() LeaserBuilder

NewInMemoryLeaserBuilder returns a new instance of inMemoryLeaserBuilder.

type LogOperation added in v0.1.1

type LogOperation string

type LogStatus added in v0.1.1

type LogStatus string

type Logger added in v0.1.14

type Logger struct {
	*zap.Logger
}

func DefaultLogger added in v0.1.1

func DefaultLogger() *Logger

func RuntimeLogger added in v0.1.11

func RuntimeLogger(runtime Runtime, operation LogOperation) *Logger

type Map

type Map[T comparable, I any] interface {
	// Get method returns the value and a boolean indicating if the key exists in the map
	Get(key T) (I, bool)
	// Set method sets a value for a key and returns the key and value as a tuple
	Set(key T, value I) (T, I)
}

func DefaultMap

func DefaultMap[T comparable, I any]() Map[T, I]

DefaultMap function returns a new inMemoryMap with an initialized map and a mutex

type Orchestrator

type Orchestrator struct {
	Name        string
	WorkerPools SafeArray[*WorkerPool]
	Strategy    Strategy
	Logger      *Logger

	Context context.Context
}

func (*Orchestrator) GetLogger added in v0.1.1

func (o *Orchestrator) GetLogger() *Logger

func (*Orchestrator) GetName added in v0.1.1

func (o *Orchestrator) GetName() string

func (*Orchestrator) GetType added in v0.1.1

func (o *Orchestrator) GetType() string

func (*Orchestrator) HandleError

func (o *Orchestrator) HandleError(err Error) Error

func (*Orchestrator) Init

func (o *Orchestrator) Init() Error

func (*Orchestrator) Run

func (o *Orchestrator) Run() Error

func (*Orchestrator) Stop

func (o *Orchestrator) Stop() Error

type Queue

type Queue[T any] interface {
	Runtime
	Receiver() <-chan T
	// Sender methods returns a reference to a chan T
	Sender() chan<- T
}

Queue was refactored and now provides 2 functions. - Receiver() - Sender()

Even though DefaultQueue is now a strange wrapper over a channel, It enables us to provide different types of queues. Queue is intended for multiple uses cases, such as abstracting a clustered Queue over the network.

func DefaultQueue

func DefaultQueue[T any](name string, ctx context.Context) Queue[T]

DefaultQueue function returns a new inMemoryQueue with an initialized channel

func DefaultQueueWithCapacity added in v0.1.27

func DefaultQueueWithCapacity[T any](name string, ctx context.Context, capacity int) Queue[T]

DefaultQueueWithCapacity function returns a new inMemoryQueue with an initialized channel

type Runtime

type Runtime interface {
	Init() Error
	Run() Error
	Stop() Error
	HandleError(Error) Error

	GetName() string
	GetType() string
	GetLogger() *Logger
}

type SafeArray added in v0.1.23

type SafeArray[T any] interface {
	Append(item T)
	Get(i int) (T, bool)
	Set(i int, item T) bool
	Slice(start, end int, stepInterval ...int) SafeArray[T]

	Length() int
}

func DefaultSafeArray added in v0.1.23

func DefaultSafeArray[T any]() SafeArray[T]

func DefaultSafeArrayWithSize added in v0.1.24

func DefaultSafeArrayWithSize[T any](size int) SafeArray[T]

type Set

type Set[T comparable] interface {
	// Exist method checks if a key exists in the Set
	Exist(key T) bool
	// Set method adds a key to the inMemorySet
	Set(key T)
	// TrySet method tries to set a key to the Set.
	// Returns true, if the key was not already set & sets it.
	// Else return false.
	TrySet(key T) bool
}

func DefaultSet

func DefaultSet[T comparable]() Set[T]

DefaultSet function returns a new inMemorySet with an initialized map and a mutex

type Strategy

type Strategy interface {
	Init(Runtime) Error
	Run(Runtime) Error
	HandleError(Runtime, Error) Error
	Stop(Runtime) Error
}

func DefaultStrategy

func DefaultStrategy() Strategy

type Worker

type Worker struct {
	Name     string
	Strategy Strategy
	Receptor Runtime
	Logger   *Logger

	Context context.Context
}

Worker is a wrapper struct around a concrete implementation of a Runtime. A Worker holds a reference to a Strategy. The Strategy is injected in the worker by the WorkerFactory

func (*Worker) GetLogger added in v0.1.1

func (w *Worker) GetLogger() *Logger

func (*Worker) GetName added in v0.1.1

func (w *Worker) GetName() string

func (*Worker) GetType added in v0.1.1

func (w *Worker) GetType() string

func (*Worker) HandleError

func (w *Worker) HandleError(err Error) Error

func (*Worker) Init

func (w *Worker) Init() Error

func (*Worker) Run

func (w *Worker) Run() Error

func (*Worker) Stop

func (w *Worker) Stop() Error

type WorkerFactory

type WorkerFactory struct {
	ReceptorFactory Builder[Runtime]
	WorkerStrategy  Strategy
}

func (*WorkerFactory) Spawn

func (f *WorkerFactory) Spawn(name string, ctx context.Context) (*Worker, Error)

type WorkerPool

type WorkerPool struct {
	Name          string
	Workers       SafeArray[*Worker]
	WorkerFactory WorkerFactory
	StrategyFunc  WorkerPoolStrategyFunc
	Replicas      int
	Logger        *Logger

	Context context.Context
}

func (*WorkerPool) GetLogger added in v0.1.1

func (p *WorkerPool) GetLogger() *Logger

func (*WorkerPool) GetName added in v0.1.1

func (p *WorkerPool) GetName() string

func (*WorkerPool) GetType added in v0.1.1

func (p *WorkerPool) GetType() string

func (*WorkerPool) HandleError

func (p *WorkerPool) HandleError(err Error) Error

func (*WorkerPool) Init

func (p *WorkerPool) Init() Error

func (*WorkerPool) Run

func (p *WorkerPool) Run() Error

func (*WorkerPool) Stop

func (p *WorkerPool) Stop() Error

type WorkerPoolStrategyFunc added in v0.1.1

type WorkerPoolStrategyFunc func(p *WorkerPool, i int, wg *sync.WaitGroup, errors SafeArray[Error])

Jump to

Keyboard shortcuts

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