conditionalflow

package
v1.36.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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

Conditional returns the workflow graph, or a mocked graph if MockConditional was called.

func (*Mock) MockConditional

func (svc *Mock) MockConditional(handler func(ctx context.Context, flow *workflow.Flow, score int) (finalBranch string, err error)) *Mock

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

func (*Mock) MockTaskA

func (svc *Mock) MockTaskA(handler func(ctx context.Context, flow *workflow.Flow, score int) (scoreOut int, err error)) *Mock

MockTaskA sets up a mock handler for TaskA.

func (*Mock) MockTaskC

func (svc *Mock) MockTaskC(handler func(ctx context.Context, flow *workflow.Flow, branch string) (finalBranch string, err error)) *Mock

MockTaskC sets up a mock handler for TaskC.

func (*Mock) MockTaskHigh

func (svc *Mock) MockTaskHigh(handler func(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)) *Mock

MockTaskHigh sets up a mock handler for TaskHigh.

func (*Mock) MockTaskLow

func (svc *Mock) MockTaskLow(handler func(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)) *Mock

MockTaskLow sets up a mock handler for TaskLow.

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

func (svc *Mock) TaskA(ctx context.Context, flow *workflow.Flow, score int) (scoreOut int, err error)

TaskA executes the mock handler.

func (*Mock) TaskC

func (svc *Mock) TaskC(ctx context.Context, flow *workflow.Flow, branch string) (finalBranch string, err error)

TaskC executes the mock handler.

func (*Mock) TaskHigh

func (svc *Mock) TaskHigh(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)

TaskHigh executes the mock handler.

func (*Mock) TaskLow

func (svc *Mock) TaskLow(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)

TaskLow executes the mock handler.

type Service

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

Service implements conditionalflow.verify, exercising when-based conditional transitions.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Conditional

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

Conditional defines the graph A -> {TaskHigh (when score>=50), TaskLow (when score<50)} -> C.

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

func (svc *Service) TaskA(ctx context.Context, flow *workflow.Flow, score int) (scoreOut int, err error)

TaskA passes the score through to state.

func (*Service) TaskC

func (svc *Service) TaskC(ctx context.Context, flow *workflow.Flow, branch string) (finalBranch string, err error)

TaskC surfaces the branch that ran.

func (*Service) TaskHigh

func (svc *Service) TaskHigh(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)

TaskHigh runs when score>=50.

func (*Service) TaskLow

func (svc *Service) TaskLow(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)

TaskLow runs when score<50.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	TaskA(ctx context.Context, flow *workflow.Flow, score int) (scoreOut int, err error)           // MARKER: TaskA
	TaskHigh(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)       // MARKER: TaskHigh
	TaskLow(ctx context.Context, flow *workflow.Flow, score int) (branch string, err error)        // MARKER: TaskLow
	TaskC(ctx context.Context, flow *workflow.Flow, branch string) (finalBranch string, err error) // MARKER: TaskC
	Conditional(ctx context.Context) (graph *workflow.Graph, err error)                            // MARKER: Conditional
}

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