handlers

package
v2.2.0-mercury-20230614 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DON

type DON interface {
	// Thread-safe
	SendToNode(ctx context.Context, nodeAddress string, msg *api.Message) error
}

Representation of a DON from a Handler's perspective.

type Handler

type Handler interface {
	job.ServiceCtx

	// Each user request is processed by a separate goroutine, which:
	//   1. calls HandleUserMessage
	//   2. waits on callbackCh with a timeout
	HandleUserMessage(ctx context.Context, msg *api.Message, callbackCh chan<- UserCallbackPayload) error

	// Handlers should not make any assumptions about goroutines calling HandleNodeMessage
	HandleNodeMessage(ctx context.Context, msg *api.Message, nodeAddr string) error
}

func NewDummyHandler

func NewDummyHandler(donConfig *config.DONConfig, don DON) (Handler, error)

func NewHandler

func NewHandler(handlerType HandlerType, donConfig *config.DONConfig, don DON) (Handler, error)

type HandlerType

type HandlerType = string
const (
	Dummy HandlerType = "dummy"
)

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(globalRPS float64, globalBurst int, perUserRPS float64, perUserBurst int) *RateLimiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(user string) bool

type UserCallbackPayload

type UserCallbackPayload struct {
	Msg     *api.Message
	ErrCode api.ErrorCode
	ErrMsg  string
}

UserCallbackPayload is a response to user request sent to HandleUserMessage(). Each message needs to receive at most one response on the provided channel.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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