uierrors

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultErrorTTL determines how long errors remain in etcd before the key expires
	DefaultErrorTTL = time.Minute * 24 * 30

	// DefaultMaxErrorHistory determines how many latest errors to return when calling GetErrorHistory()
	DefaultMaxErrorHistory = 1000
)

Variables

View Source
var (
	ErrMissingError      = errors.New("error cannot be empty")
	ErrMissingResource   = errors.New("resource cannot be empty")
	ErrMissingResourceID = errors.New("resource ID cannot be empty")
	ErrMissingEtcd       = errors.New("EtcdService cannot be nil")
)

Functions

This section is empty.

Types

type AttachedStream

type AttachedStream struct {
	MessageCh chan *protos.ErrorMessage
}

AttachedStream is used to hold a channel which sends protos.ErrorMessage for a gRPC stream to receive

type Config

type Config struct {
	EtcdService etcd.IEtcd
}

Config is used to pass required options to New()

type IUIErrors

type IUIErrors interface {
	AddError(msg *protos.ErrorMessage) error
	ConnectClient(id string) *AttachedStream
	DisconnectClient(id string)
	GetHistory(ctx context.Context) ([]*protos.ErrorMessage, error)
}

type UIErrors

type UIErrors struct {
	*Config
	AttachedClientsMtx *sync.RWMutex
	AttachedClients    map[string]*AttachedStream
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) (*UIErrors, error)

New instantiates the uierrors service

func (*UIErrors) AddError

func (u *UIErrors) AddError(msg *protos.ErrorMessage) error

AddError is called by plumber code where we need to send an error to the client

func (*UIErrors) ConnectClient

func (u *UIErrors) ConnectClient(id string) *AttachedStream

ConnectClient is called whenever the streaming gRPC endpoint GetErrors() is called. A new AttachedClient will be added to the AttachedClients. Any stored messages in etcd will be read, sent to the client, and then deleted from etcd.

func (*UIErrors) DisconnectClient

func (u *UIErrors) DisconnectClient(id string)

DisconnectClient removes an attached client from the map, and cleans up the channel

func (*UIErrors) GetHistory

func (u *UIErrors) GetHistory(ctx context.Context) ([]*protos.ErrorMessage, error)

GetHistory reads all error messages stored in etcd

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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