maxconcurrencyflow

package
v1.37.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Hostname = maxconcurrencyflowapi.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) Bounded

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

Bounded executes the mock handler.

func (*Mock) MaxConcurrency

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

MaxConcurrency returns the workflow graph, or a mocked graph if MockMaxConcurrency was called.

func (*Mock) MockBounded

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

MockBounded sets up a mock handler for Bounded.

func (*Mock) MockMaxConcurrency

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

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

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.

type Service

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

Service implements maxconcurrencyflow.verify, exercising adaptive per-task concurrency control via a task that self-emits 429 above a configured cap.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Bounded

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

Bounded admits up to cap concurrent in-flight executions. Above that it returns http.StatusTooManyRequests so the foreman observes a 429 and exercises its backpressure path. While admitted, the task sleeps to overlap with peers.

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) MaxConcurrency

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

MaxConcurrency defines the single-task graph (bounded -> END) used to drive the foreman through the backpressure path.

func (*Service) Observed

func (svc *Service) Observed() (peak int, rejections int)

Observed returns (peak in-flight observed, total 429 rejections emitted).

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) SetCap

func (svc *Service) SetCap(cap int) *Service

SetCap configures the task's self-limit. Above this concurrent count, Bounded returns 429. Must be called before app.RunInTest. Returns the service for chaining inside Init.

func (*Service) SetDwell

func (svc *Service) SetDwell(d time.Duration) *Service

SetDwell configures how long Bounded sleeps while in flight (simulates work). Longer dwell increases the odds of concurrent dispatches overlapping.

type ToDo

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

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