README
¶
Flows
This package makes handling flows super simple. 😎
Flow: The "Flow" represents the entire journey of an API request, from its initial receipt to the final response generation. It encapsulates the sequence of operations and transformations that occur during the processing of the request.
Step: A "Step" is a single, distinct action or operation that contributes to the overall Flow. It's a building block of the larger process, representing a specific stage or task within the API's business logic.
Installation
Get the package
go get go.alis.build/flows
Import the package
import "go.alis.build/flows"
Create a new Sproto instance using NewClient
// Create new client
client, err := NewClient(project, WithTopic("flows"))
if err != nil {}
Usage
Create a new flow.
flow, err := client.NewFlow(ctx)
if err != nil {}
Add a step to the flow.
step := flow.NewStep("1.0", "Step 1")
Set step state
step = step.Queued()
Publish the flow
err := flow.Publish()
Documentation
¶
Overview ¶
Package flows provides a lightweight set of methods which Builders can use to represent the entire journey of an API request, from its initial receipt to the final response generation. It encapsulates the sequence of operations and transformations that occur during the processing of the request.
Index ¶
- Constants
- type Client
- type Flow
- type Option
- type Options
- type Step
- func (s *Step) AwaitingInput() *Step
- func (s *Step) Cancelled() *Step
- func (s *Step) Done() *Step
- func (s *Step) Failed(err error) *Step
- func (s *Step) InProgress() *Step
- func (s *Step) Publish() error
- func (s *Step) Queued() *Step
- func (s *Step) WithDescription(description string) *Step
- func (s *Step) WithTitle(title string) *Step
Constants ¶
const ( DefaultTopic = "flows" FlowParentHeaderKey = "x-alis-flow-parent" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client object to manage Publishing to a Pub/Sub topic.
func NewClient ¶
NewClient creates a new instance of the Client object.
Multiple Option functions can be provided to customize the client. For example: WithTopic("flows")
type Flow ¶
type Flow struct {
// contains filtered or unexported fields
}
func (*Flow) NewStep ¶
NewStep adds a step to the flow and returns a Step object.
The initial state of the step is Queued.
func (*Flow) WithParentId ¶
WithParentId sets the parent id of the flow.
This overrides the inferred parent id from the x-alis-flows-id header.
func (*Flow) WithSource ¶
WithSource sets the source of the flow.
This overrides the inferred source from the invoking method.
type Option ¶
type Option func(*Options)
Option is a functional option for the NewClient method.
func WithAwaitPublish ¶
func WithAwaitPublish() Option
WithAwaitPublish instructs the client to block until the flow is finished publishing. This causes the client to block until the Publish call completes or the context is done.
type Options ¶
type Options struct { // The Pub/Sub Topic // For example: 'flows' // // Defaults to 'progress' if not specified. Topic string // Indicates whether the pubsub client should block until the message is published. // If set to true, the client will block until the message is published or the context is done. // If set to false, the client will return immediately after the message is published. AwaitPublish bool }
Options for the NewClient method.
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
Step represents a single step within the Flow object.
func (*Step) AwaitingInput ¶
AwaitingInput marks the state of the step as Awaiting Input.
func (*Step) InProgress ¶
InProgress marks the state of the step as In Progress.