shared

package
v2.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package shared provides everything shared between entities.

Index

Constants

This section is empty.

Variables

View Source
var Paused int32 = 0

Paused is a flag that indicates if the pipeline is paused.

Functions

func Decode

func Decode(r io.Reader, v any) error

Decode process stream `r` into `v` and returns an error if any.

func Encode

func Encode(w io.Writer, v any) error

Encode process `v` into stream `w` and returns an error if any.

func ExtractID

func ExtractID[T any](t T, idFieldName string) string

ExtractID extracts `possibleIDFieldNames` from `v` - an arbitrary struct.

NOTE: Only exported fields are considered.

func Flatten2D

func Flatten2D[T any](data [][]T) []T

Flatten2D takes a 2D slice and returns a 1D slice containing all the elements.

func GenerateIDBasedOnContent

func GenerateIDBasedOnContent(ct string) string

GenerateIDBasedOnContent generates MD5 hash (content-based) for message ID. Good to be used to avoid duplicated messages.

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates a RFC4122 UUID and DCE 1.1: Authentication and Security Services.

func GetPaused

func GetPaused() int32

GetPaused returns the `Paused` flag. It's concurrency-safe.

func Marshal

func Marshal(v any) ([]byte, error)

Marshal with custom error.

func OnErrorHandler added in v2.1.0

func OnErrorHandler(
	tracedContext context.Context,
	iMetric IMetrics,
	l sypl.ISypl,
	err error,
	message, t, name string,
) error

OnErrorHandler deals with observability (update status, logging, metrics) when an processor, or stage, or the pipeline error.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads all the data from `r` and returns an error if any.

func SetPaused

func SetPaused(val int32)

SetPaused sets the `Paused` flag. It's concurrency-safe.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal with custom error.

Types

type IMeta

type IMeta interface {
	// GetName returns the `Name` of the entity.
	GetName() string

	// GetLogger returns the `Logger` of the entity.
	GetLogger() sypl.ISypl

	// GetDescription returns the `Description` of the processor.
	GetDescription() string

	// GetType returns the entity type.
	GetType() string
}

IMeta defines what an `Entity` must do.

type IMetrics

type IMetrics interface {
	// GetCounterCreated returns the `CounterCreated` metric.
	GetCounterCreated() *expvar.Int

	// GetCounterRunning returns the `CounterRunning` metric.
	GetCounterRunning() *expvar.Int

	// GetCounterFailed returns the `CounterFailed` metric.
	GetCounterFailed() *expvar.Int

	// GetCounterDone returns the `CounterDone` metric.
	GetCounterDone() *expvar.Int

	// GetStatus returns the `Status` metric.
	GetStatus() *expvar.String

	// GetCreatedAt returns the created at time.
	GetCreatedAt() time.Time

	// GetDuration returns the `CounterDuration` of the stage.
	GetDuration() *expvar.Int

	// GetMetrics returns the stage's metrics.
	GetMetrics() map[string]string
}

IMetrics defines how to interact with the metrics.

Jump to

Keyboard shortcuts

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