sleepflow

package
v1.32.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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

Delay returns the workflow graph, or a mocked graph if MockDelay was called.

func (*Mock) MockDelay

func (svc *Mock) MockDelay(handler func(ctx context.Context, flow *workflow.Flow, sleepFor time.Duration) (completed bool, err error)) *Mock

MockDelay sets up a mock handler for the Delay 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, sleepFor time.Duration) (sleepForOut time.Duration, err error)) *Mock

MockTaskA sets up a mock handler for TaskA.

func (*Mock) MockTaskB

func (svc *Mock) MockTaskB(handler func(ctx context.Context, flow *workflow.Flow, sleepFor time.Duration) (marked bool, err error)) *Mock

MockTaskB sets up a mock handler for TaskB.

func (*Mock) MockTaskC

func (svc *Mock) MockTaskC(handler func(ctx context.Context, flow *workflow.Flow, marked bool) (completed bool, err error)) *Mock

MockTaskC sets up a mock handler for TaskC.

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, sleepFor time.Duration) (sleepForOut time.Duration, err error)

TaskA executes the mock handler.

func (*Mock) TaskB

func (svc *Mock) TaskB(ctx context.Context, flow *workflow.Flow, sleepFor time.Duration) (marked bool, err error)

TaskB executes the mock handler.

func (*Mock) TaskC

func (svc *Mock) TaskC(ctx context.Context, flow *workflow.Flow, marked bool) (completed bool, err error)

TaskC executes the mock handler.

type Service

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

Service implements sleepflow.verify, exercising flow.Sleep.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) Delay

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

Delay defines the graph A -> B -> C with B calling flow.Sleep before C runs. The workflow is named Delay (not Sleep) to avoid colliding with the connector's own Sleep method.

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, sleepFor time.Duration) (sleepForOut time.Duration, err error)

TaskA passes the sleep duration through.

func (*Service) TaskB

func (svc *Service) TaskB(ctx context.Context, flow *workflow.Flow, sleepFor time.Duration) (marked bool, err error)

TaskB calls flow.Sleep(sleepFor) to delay TaskC's dispatch.

func (*Service) TaskC

func (svc *Service) TaskC(ctx context.Context, flow *workflow.Flow, marked bool) (completed bool, err error)

TaskC runs after the sleep elapses.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	TaskA(ctx context.Context, flow *workflow.Flow, sleepFor time.Duration) (sleepForOut time.Duration, err error) // MARKER: TaskA
	TaskB(ctx context.Context, flow *workflow.Flow, sleepFor time.Duration) (marked bool, err error)               // MARKER: TaskB
	TaskC(ctx context.Context, flow *workflow.Flow, marked bool) (completed bool, err error)                       // MARKER: TaskC
	Delay(ctx context.Context) (graph *workflow.Graph, err error)                                                  // MARKER: Delay
}

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