flows

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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

func NewClient(project string, opts ...Option) (*Client, error)

NewClient creates a new instance of the Client object.

Multiple Option functions can be provided to customize the client. For example: WithTopic("flows")

func (*Client) NewFlow

func (c *Client) NewFlow(ctx context.Context) (*Flow, error)

NewFlow creates a new Flow object

The source is inferred from the invoking method. This can be overridden by calling WithSource.

The parent id is inferred from the x-alis-flows-id header. This can be overridden by calling WithParentId.

type Flow

type Flow struct {
	// contains filtered or unexported fields
}

func (*Flow) NewStep

func (f *Flow) NewStep(id string, title string) (*Step, context.Context)

NewStep adds a step to the flow and returns a Step object.

The initial state of the step is Queued.

func (*Flow) Publish

func (f *Flow) Publish() error

Publish the Flow as an event.

func (*Flow) WithParentId

func (f *Flow) WithParentId(parentId string) *Flow

WithParentId sets the parent id of the flow.

This overrides the inferred parent id from the x-alis-flows-id header.

func (*Flow) WithSource

func (f *Flow) WithSource(source string) *Flow

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.

func WithTopic

func WithTopic(topic string) Option

WithTopic sets the topic for the client.

If provided multiple times, the last value will take precedence.

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

func (s *Step) AwaitingInput() *Step

AwaitingInput marks the state of the step as Awaiting Input.

func (*Step) Cancelled

func (s *Step) Cancelled() *Step

Cancelled marks the state of the step as Queued.

func (*Step) Done

func (s *Step) Done() *Step

Done marks the state of the step as done.

func (*Step) Failed

func (s *Step) Failed(err error) *Step

Failed marks the lasted step as Failed with the specified error.

func (*Step) InProgress

func (s *Step) InProgress() *Step

InProgress marks the state of the step as In Progress.

func (*Step) Publish

func (s *Step) Publish() error

Publish allows one to publish a particular step.

func (*Step) Queued

func (s *Step) Queued() *Step

Queued marks the state of the step as Queued.

func (*Step) WithDescription

func (s *Step) WithDescription(description string) *Step

func (*Step) WithTitle

func (s *Step) WithTitle(title string) *Step

WithTitle sets the title of the step.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL