workflows

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RetryForever int32 = 0 // Default workflow max Attempts. 0 means forever.
)

Variables

View Source
var (
	// ErrParentNil is returned when the parent workflow context is nil.
	ErrParentNil = errors.New("parent workflow context is nil")
)

Functions

func NewDuplicateIDPropError

func NewDuplicateIDPropError(prop, value, next string) error

func Sanitize added in v0.5.1

func Sanitize(input string) string

Sanitize converts a string to snake_case, preserving hyphens and handling various edge cases. It is intended for use in generating unique identifiers for elements, modifiers, and blocks.

Types

type DuplicateIDPropError

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

func (*DuplicateIDPropError) Error

func (e *DuplicateIDPropError) Error() string

type Option

type Option func(Options) error

Option sets the specified options.

func WithBlock

func WithBlock(val string) Option

WithBlock sets the block name.

func WithBlockID

func WithBlockID(val string) Option

WithBlockID sets the block value.

func WithElement

func WithElement(val string) Option

WithElement sets the element name.

func WithElementID

func WithElementID(val string) Option

WithElementID sets the element value.

func WithIgnoredError

func WithIgnoredError(err string) Option

WithIgnoredError adds an error to the list of errors that are ok to ignore for the workflow.

func WithMaxAttempts

func WithMaxAttempts(attempts int32) Option

WithMaxAttempts sets the max attempts for the workflow.

func WithMod

func WithMod(val string) Option

WithMod sets the modifier name.

func WithModID

func WithModID(val string) Option

WithModID sets the modifier value.

func WithParent

func WithParent(parent workflow.Context) Option

WithParent sets the parent workflow context.

func WithProp

func WithProp(key, val string) Option

WithProp sets the prop given a key & value.

type Options

type Options interface {
	IsChild() bool            // IsChild returns true if the workflow id is a child workflow id.
	ParentWorkflowID() string // ParentWorkflowID returns the parent workflow id.
	IDSuffix() string         // IDSuffix santizes the suffix of the workflow id and then formats it as a string.
	MaxAttempts() int32       // MaxAttempts returns the max attempts for the workflow.
	IgnoredErrors() []string  // IgnoredErrors returns the list of errors that are ok to ignore.
}

Options defines the interface for creating workflow options.

func NewOptions

func NewOptions(opts ...Option) (Options, error)

NewOptions sets workflow options required to run a workflow like workflow id, max attempts, etc.

The idempotent workflow ID Sometimes we need to signal the workflow from a completely disconnected part of the application. For us, it is important to arrive at the same workflow ID regardless of the conditions. We try to follow the block, element, modifier pattern popularized by advocates of maintainable CSS. For more info, https://getbem.com/.

Example: For the block github with installation id 123, the element being the repository with id 456, and the modifier being the pull request with id 789, we would call

opts := NewOptions(
  WithBlock("github"),
  WithBlockID("123"),
  WithElement("repository"),
  WithElementID("456"),
  WithModifier("repository"),
  WithModifierID("789"),
  // Sometimes we need to over-ride max attempts. The default is workflows.RetryForever.
  WithMaxAttempts(3),
  // If we want to ignore an error, we can do so.
  WithIgnoredError("SomeError"),
)

id := opts.ID()

NOTE: The design is work in progress and may change in future.

Jump to

Keyboard shortcuts

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