processor

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package processor provides a framework for creating processors.

Index

Constants

View Source
const Type = "processor"

Type of the entity.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func added in v0.1.0

type Func[T any] func(p IProcessor[T]) IProcessor[T]

Func allows to specify message's options.

func WithOnFinished added in v0.1.0

func WithOnFinished[T any](onFinished OnFinished[T]) Func[T]

WithOnFinished sets the OnFinished function.

type IProcessor

type IProcessor[In any] interface {
	shared.IMeta

	shared.IMetrics

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

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

	// Run the transform function.
	Run(ctx context.Context, in []In) (out []In, err error)
}

IProcessor defines what a `Processor` must do.

func New

func New[T any](
	name string,
	description string,
	fn shared.Run[T],
	opts ...Func[T],
) (IProcessor[T], error)

New returns a new processor.

type OnFinished added in v0.1.0

type OnFinished[T any] func(ctx context.Context, p IProcessor[T], originalIn []T, processedIn []T)

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

type Processor

type Processor[T any] struct {
	// Description of the processor.
	Description string `json:"description"`

	// Transform function.
	Func shared.Run[T] `json:"-"`

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

	// Name of the processor.
	Name string `json:"name"`

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

	// Metrics.
	CounterCreated *expvar.Int    `json:"counterCreated" validate:"required,gte=0"`
	CounterRunning *expvar.Int    `json:"counterRunning" validate:"required,gte=0"`
	CounterFailed  *expvar.Int    `json:"counterFailed" validate:"required,gte=0"`
	CounterDone    *expvar.Int    `json:"counterDone" validate:"required,gte=0"`
	Status         *expvar.String `json:"status" validate:"required,gte=0"`
}

Processor definition.

func (*Processor[T]) GetCounterCreated added in v0.1.0

func (p *Processor[T]) GetCounterCreated() *expvar.Int

GetCounterCreated returns the `CounterCreated` metric.

func (*Processor[T]) GetCounterDone added in v0.1.0

func (p *Processor[T]) GetCounterDone() *expvar.Int

GetCounterDone returns the `CounterDone` metric.

func (*Processor[T]) GetCounterFailed added in v0.1.0

func (p *Processor[T]) GetCounterFailed() *expvar.Int

GetCounterFailed returns the `CounterFailed` metric.

func (*Processor[T]) GetCounterRunning added in v0.1.0

func (p *Processor[T]) GetCounterRunning() *expvar.Int

GetCounterRunning returns the `CounterRunning` metric.

func (*Processor[T]) GetDescription

func (p *Processor[T]) GetDescription() string

GetDescription returns the `Description` of the processor.

func (*Processor[T]) GetLogger added in v0.1.0

func (p *Processor[T]) GetLogger() sypl.ISypl

GetLogger returns the `Logger` of the processor.

func (*Processor[T]) GetName

func (p *Processor[T]) GetName() string

GetName returns the `Name` of the processor.

func (*Processor[T]) GetOnFinished added in v0.1.0

func (p *Processor[T]) GetOnFinished() OnFinished[T]

GetOnFinished returns the `OnFinished` function.

func (*Processor[T]) GetStatus added in v0.1.0

func (p *Processor[T]) GetStatus() *expvar.String

GetStatus returns the `Status` metric.

func (*Processor[T]) GetType added in v0.1.2

func (p *Processor[T]) GetType() string

GetType returns the entity type.

func (*Processor[T]) Run

func (p *Processor[T]) Run(ctx context.Context, t []T) ([]T, error)

Run the transform function.

func (*Processor[T]) SetOnFinished added in v0.1.0

func (p *Processor[T]) SetOnFinished(onFinished OnFinished[T])

SetOnFinished sets the `OnFinished` function.

Jump to

Keyboard shortcuts

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