timebudgetflow

package
v1.35.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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

MockSlow sets up a mock handler for Slow.

func (*Mock) MockTaskA

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

MockTaskA sets up a mock handler for TaskA.

func (*Mock) MockTimeBudget

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

MockTimeBudget sets up a mock handler for the TimeBudget 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.

func (*Mock) Slow

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

Slow executes the mock handler.

func (*Mock) TaskA

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

TaskA executes the mock handler.

func (*Mock) TimeBudget

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

TimeBudget returns the workflow graph, or a mocked graph if MockTimeBudget was called.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove
}

Service implements timebudgetflow.verify, exercising per-task time budgets.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

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

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

Slow sleeps for 500ms, well beyond the 50ms budget the Slow endpoint declares via sub.TimeBudget. The connector shortens the inbound context deadline to that budget; the task observes the cancellation and returns ctx.Err(), which the foreman surfaces as a step failure with status 408.

func (*Service) TaskA

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

TaskA is the entry point.

func (*Service) TimeBudget

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

TimeBudget defines A -> Slow. The Slow endpoint declares its own 50ms budget via sub.TimeBudget, so the graph carries no timing.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	TaskA(ctx context.Context, flow *workflow.Flow) (started bool, err error) // MARKER: TaskA
	Slow(ctx context.Context, flow *workflow.Flow) (done bool, err error)     // MARKER: Slow
	TimeBudget(ctx context.Context) (graph *workflow.Graph, err error)        // MARKER: TimeBudget
}

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