loader

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package loader provides a framework for creating loaders.

Index

Constants

View Source
const Type = "loader"

Type of the entity.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func[In, Out any] func(p ILoader[In, Out]) ILoader[In, Out]

Func allows to specify message's options.

func WithOnFinished

func WithOnFinished[In, Out any](onFinished OnFinished[In, Out]) Func[In, Out]

WithOnFinished sets the OnFinished function.

type ILoader

type ILoader[In, Out any] interface {
	shared.IMeta

	shared.IMetrics

	// GetOnFinished returns the `OnFinished` function.
	GetOnFinished() OnFinished[In, Out]

	// SetOnFinished sets the `OnFinished` function.
	SetOnFinished(onFinished OnFinished[In, Out])

	// Run the stage function.
	Run(ctx context.Context, in In) (Out, error)
}

ILoader defines what a `Conveter` must do.

func New

func New[In, Out any](
	name, description string,
	fn Load[In, Out],
	opts ...Func[In, Out],
) (ILoader[In, Out], error)

New returns a new stage.

type Load

type Load[In, Out any] func(ctx context.Context, in In) (out Out, err error)

Load is a function that converts the data (`in`). It returns the converted data and any errors that occurred during conversion.

type Loader

type Loader[In, Out any] struct {
	// Description of the processor.
	Description string `json:"description"`

	// Conversion function.
	Func Load[In, Out] `json:"-"`

	// Logger is the internal logger.
	Logger sypl.ISypl `json:"-" validate:"required"`

	// Name of the stage.
	Name string `json:"name" validate:"required"`

	// OnFinished is the function that is called when a processor finishes its
	// execution.
	OnFinished OnFinished[In, Out] `json:"-"`

	// Metrics.
	CounterCreated *expvar.Int `json:"counterCreated"`
	CounterRunning *expvar.Int `json:"counterRunning"`
	CounterFailed  *expvar.Int `json:"counterFailed"`
	CounterDone    *expvar.Int `json:"counterDone"`

	CreatedAt time.Time      `json:"createdAt"`
	Duration  *expvar.Int    `json:"duration"`
	Status    *expvar.String `json:"status"`
}

Loader definition.

func (*Loader[In, Out]) GetCounterCreated

func (c *Loader[In, Out]) GetCounterCreated() *expvar.Int

GetCounterCreated returns the `CounterCreated` of the processor.

func (*Loader[In, Out]) GetCounterDone

func (c *Loader[In, Out]) GetCounterDone() *expvar.Int

GetCounterDone returns the `CounterDone` of the processor.

func (*Loader[In, Out]) GetCounterFailed

func (c *Loader[In, Out]) GetCounterFailed() *expvar.Int

GetCounterFailed returns the `CounterFailed` of the processor.

func (*Loader[In, Out]) GetCounterRunning

func (c *Loader[In, Out]) GetCounterRunning() *expvar.Int

GetCounterRunning returns the `CounterRunning` of the processor.

func (*Loader[In, Out]) GetCreatedAt

func (c *Loader[In, Out]) GetCreatedAt() time.Time

GetCreatedAt returns the created at time.

func (*Loader[In, Out]) GetDescription

func (c *Loader[In, Out]) GetDescription() string

GetDescription returns the `Description` of the processor.

func (*Loader[In, Out]) GetDuration

func (c *Loader[In, Out]) GetDuration() *expvar.Int

GetDuration returns the `CounterDuration` of the stage.

func (*Loader[In, Out]) GetLogger

func (c *Loader[In, Out]) GetLogger() sypl.ISypl

GetLogger returns the `Logger` of the processor.

func (*Loader[In, Out]) GetMetrics

func (c *Loader[In, Out]) GetMetrics() map[string]string

GetMetrics returns the stage's metrics.

func (*Loader[In, Out]) GetName

func (c *Loader[In, Out]) GetName() string

GetName returns the `Name` of the stage.

func (*Loader[In, Out]) GetOnFinished

func (c *Loader[In, Out]) GetOnFinished() OnFinished[In, Out]

GetOnFinished returns the `OnFinished` function.

func (*Loader[In, Out]) GetStatus

func (c *Loader[In, Out]) GetStatus() *expvar.String

GetStatus returns the `Status` metric.

func (*Loader[In, Out]) GetType

func (c *Loader[In, Out]) GetType() string

GetType returns the entity type.

func (*Loader[In, Out]) Run

func (c *Loader[In, Out]) Run(ctx context.Context, in In) (Out, error)

Run the conversion function.

func (*Loader[In, Out]) SetOnFinished

func (c *Loader[In, Out]) SetOnFinished(onFinished OnFinished[In, Out])

SetOnFinished sets the `OnFinished` function.

type OnFinished

type OnFinished[In, Out any] func(ctx context.Context, c ILoader[In, Out], originalIn In, convertedOut Out)

OnFinished is the function that is called when a processor finishes its execution.

Jump to

Keyboard shortcuts

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