fairnessflow

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hostname = fairnessflowapi.Hostname
	Version  = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) Fairness

func (svc *Mock) Fairness(ctx context.Context) (graph *workflow.Graph, err error)

Fairness returns the workflow graph, or a mocked graph if MockFairness was called.

func (*Mock) MockFairness

func (svc *Mock) MockFairness(handler func(ctx context.Context, flow *workflow.Flow, tag string, delayMs int) (tallied bool, err error)) *Mock

MockFairness sets up a mock handler for the Fairness workflow. The handler receives typed inputs from the workflow's state and returns typed outputs. A nil handler clears the mock.

func (*Mock) MockTally

func (svc *Mock) MockTally(handler func(ctx context.Context, flow *workflow.Flow) (tallied bool, err error)) *Mock

MockTally sets up a mock handler for Tally.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Mock) Tally

func (svc *Mock) Tally(ctx context.Context, flow *workflow.Flow) (tallied bool, err error)

Tally executes the mock handler.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove
	// contains filtered or unexported fields
}

Service implements fairnessflow.verify, exercising two-level weighted fairness across fairness keys.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Fairness

func (svc *Service) Fairness(ctx context.Context) (graph *workflow.Graph, err error)

Fairness defines the single-task graph (tally -> END) used to observe weighted dispatch share across fairness keys. The graph carries no timing; the fairness key and weight are per-flow options at Create.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) Order

func (svc *Service) Order() []string

Order returns the tags in the order their flows were dispatched, oldest first.

func (*Service) Tally

func (svc *Service) Tally(ctx context.Context, flow *workflow.Flow) (tallied bool, err error)

Tally sleeps for the requested delay, then appends its key tag to the dispatch order. The delay forces saturation so the order in which a single worker picks up flows reflects the foreman's weighted fairness selection across keys, not arrival timing.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	Tally(ctx context.Context, flow *workflow.Flow) (tallied bool, err error) // MARKER: Tally
	Fairness(ctx context.Context) (graph *workflow.Graph, err error)          // MARKER: Fairness
}

ToDo is implemented by the service or mock.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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