looper

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package looper provider the building blocks for the adapter's looper.

Index

Constants

View Source
const Name = "requester"

Name of the looper.

View Source
const Type = "looper"

Type of the entity in the framework.

Variables

View Source
var ErrHTTPVerbNotImplemented = errors.New("http verb not implemented")

ErrHTTPVerbNotImplemented is the error returned when the http verb is not implemented by the underlying http client.

Functions

func Switcher

func Switcher(
	ctx context.Context,
	logger sypl.ISypl,
	httpVerb string,
	url string,
	hc *httpclient.Client,
	o ...httpclient.Func,
) (*http.Response, error)

Switcher determines which request to run.

Types

type Func

type Func func(IMetrics)

Func is the function which is executed by the looper.

type ILooper

type ILooper interface {
	// Start starts the loop.
	Start()

	// StartAsync starts the loop asynchronously.
	StartAsync()

	// Stop stops the loop.
	Stop()
}

ILooper is the interface of the looper.

func New

func New(
	name string,
	interval time.Duration,
	enableMetrics bool,
	loggingLevel string,
	metricsServerPort string,
	fn Func,
) (ILooper, error)

New creates a new Looper.

func NewRequester

func NewRequester(
	httpVerb string,
	url string,
	interval time.Duration,
	enableMetrics bool,
	loggingLevel string,
	metricsServerPort string,
	o ...httpclient.Func,
) (ILooper, error)

NewRequester creates a new requester.

type IMetrics

type IMetrics interface {
	// GetLogger returns the logger of the looper.
	GetLogger() sypl.ISypl

	// IncrementFailedCounter increments the failed counter.
	IncrementFailedCounter()

	// IncrementSuccessCounter increments the success counter.
	IncrementSuccessCounter()

	// IncrementTotalCounter increments the total counter.
	IncrementTotalCounter()
}

IMetrics is the interface of the metrics.

type Looper

type Looper struct {
	// Func is the function to be executed.
	Func Func `json:"-" validate:"required"`

	// Interval is the time between each loop.
	Interval time.Duration `json:"interval"`

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

	// Name of the looper.
	Name string `json:"name" validate:"required,lowercase,gte=1"`

	*Metrics
	// contains filtered or unexported fields
}

Looper is the individual, concurrent/non-blocking. The primary goal is to check the status of the API.

func (*Looper) GetLogger

func (l *Looper) GetLogger() sypl.ISypl

GetLogger returns the logger of the looper.

func (*Looper) GetMetrics

func (l *Looper) GetMetrics() any

GetMetrics returns the metrics of the looper.

func (*Looper) IncrementFailedCounter

func (l *Looper) IncrementFailedCounter()

IncrementFailedCounter increments the failed counter.

func (*Looper) IncrementSuccessCounter

func (l *Looper) IncrementSuccessCounter()

IncrementSuccessCounter increments the success counter.

func (*Looper) IncrementTotalCounter

func (l *Looper) IncrementTotalCounter()

IncrementTotalCounter increments the total counter.

func (*Looper) Start

func (l *Looper) Start()

Start the loop.

func (*Looper) StartAsync

func (l *Looper) StartAsync()

StartAsync the loop.

func (*Looper) Stop

func (l *Looper) Stop()

Stop the loop.

type Metrics

type Metrics struct {
	// Failed will be incremented every time a it fails execution.
	FailedCounter *expvar.Int `json:"-" validate:"omitempty,gte=0"`

	// Succeeded will be incremented every time a it succeeds execution.
	SuccessCounter *expvar.Int `json:"-" validate:"omitempty,gte=0"`

	// Total will be incremented every time a it is executed.
	TotalCounter *expvar.Int `json:"-" validate:"omitempty,gte=0"`
}

Metrics contains the metrics of a loop.

type Requester

type Requester struct {
	ILooper
}

Requester is the requester looper.

Jump to

Keyboard shortcuts

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