workflow

package
v0.0.0-...-1d0517d Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package workflow provides a workflow plan that can be executed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewV7

func NewV7() uuid.UUID

NewV7 generates a new UUID. This is a wrapper around uuid.NewV7 that retries until a valid UUID is generated.

func Secure

func Secure(v *Plan)

Secure sets all fields in anywhere in the Plan that are tagged with `coerce:"secure"` to their zero value.

func Validate

func Validate(p *Plan) error

Validate validates the Plan. This is automatically called by workstream.Submit.

Types

type Action

type Action struct {
	// ID is a unique identifier for the object. Should not be set by the user.
	ID uuid.UUID
	// Key is a unique identifier within a Plan that the user supplies and can use to reference
	// the action. Optional.
	Key uuid.UUID
	// Name is the name of the Action. Required.
	Name string
	// Descr is a description of the Action. Required.
	Descr string
	// Plugin is the name of the plugin that is executed. Required.
	Plugin string
	// Timeout is the amount of time to wait for the Action to complete. This defaults to 30 seconds and
	// must be at least 5 seconds.
	Timeout time.Duration `json:",format:iso8601"`
	// Retries is the number of times to retry the Action if it fails. This defaults to 0.
	Retries int
	// Req is the request object that is passed to the plugin.
	Req any
	// Attempts is the attempts of the action. This should not be set by the user.
	Attempts []*Attempt
	// State represents settings that should not be set by the user, but users can query.
	State *State
	// contains filtered or unexported fields
}

Action represents a single action that is executed by a plugin.

func (*Action) Defaults

func (a *Action) Defaults()

Defaults sets the default values for the object. For use internally.

func (*Action) Equal

func (a *Action) Equal(other *Action) bool

Equal returns true if the Action objects are equal. Only compares public fields.

func (*Action) FinalAttempt

func (a *Action) FinalAttempt() *Attempt

FinalAttempt returns the last attempt of the action.

func (*Action) GetID

func (a *Action) GetID() uuid.UUID

GetID is a getter for the ID field.

func (*Action) GetPlanID

func (a *Action) GetPlanID() uuid.UUID

GetPlanID returns the Plan ID that the object belongs to.

func (*Action) GetState

func (a *Action) GetState() *State

GetState is a getter for the State settings.

func (*Action) HasRegister

func (a *Action) HasRegister() bool

HasRegister determines if a Register has been set.

func (*Action) SetID

func (a *Action) SetID(id uuid.UUID)

SetID is a setter for the ID field. This should not be used by the user.

func (*Action) SetPlanID

func (a *Action) SetPlanID(u uuid.UUID)

SetPlanID sets the Plan ID that the object belongs to. This should not be used by the user.

func (*Action) SetRegister

func (a *Action) SetRegister(r *registry.Register)

SetRegister sets the register for the Action. This should not be used by the user except in tests.

func (*Action) SetState

func (a *Action) SetState(state *State)

SetState is a setter for the State settings.

func (*Action) Type

func (a *Action) Type() ObjectType

Type implements the Object.Type().

type Attempt

type Attempt struct {
	// Resp is the response object that is returned by the plugin.
	Resp any
	// Err is the plugin error that is returned by the plugin. If this is not nil, the attempt failed.
	Err *plugins.Error

	// Start is the time the attempt started.
	Start time.Time
	// End is the time the attempt ended.
	End time.Time
}

Attempt is the result of an action that is executed by a plugin. Nothing in Attempt should be set by the user.

func (*Attempt) Equal

func (a *Attempt) Equal(other *Attempt) bool

Equal returns true if the Attempt objects are equal. Only compares public fields.

type Block

type Block struct {
	// ID is a unique identifier for the object. Should not be set by the user.
	ID uuid.UUID
	// Key is a unique identifier within a Plan that the user supplies and can use to reference
	// the block. Optional.
	Key uuid.UUID
	// Name is the name of the block. Required.
	Name string
	// Descr is a description of the block. Required.
	Descr string

	// EntranceDelay is the amount of time to wait before the block starts. This defaults to 0.
	EntranceDelay time.Duration `json:",format:iso8601"`
	// ExitDelay is the amount of time to wait after the block has completed. This defaults to 0.
	ExitDelay time.Duration `json:",format:iso8601"`

	// BypassChecks are actions that if they succeed will cause the block to be skipped.
	// If any gate fails, the workflow will be executed. Optional.
	BypassChecks *Checks
	// PreChecks are actions that are executed before the block starts.
	// Any error will cause the block to fail. Optional.
	PreChecks *Checks
	// Checks are actions that are executed while the block is running. Optional.
	ContChecks *Checks
	// PostChecks are actions that are executed after the block has completed.
	// Any error will cause the block to fail. Optional.
	PostChecks *Checks
	// DeferredChecks are actions that are executed after the workflow has completed.
	// This is executed regardless of Plan success or failure. However, if the
	// Block is bypassed via BypassChecks, this will not run.
	// Useful for logging and similar operations. Optional.
	DeferredChecks *Checks

	// Sequences is a list of sequences that are executed. Required..
	Sequences []*Sequence

	// Concurrency is the number of sequences that are executed in parallel. This defaults to 1.
	Concurrency int
	// ToleratedFailures is the number of sequences that are allowed to fail before the block fails. This defaults to 0.
	// If set to -1, all sequences are allowed to fail.
	ToleratedFailures int

	// State represents settings that should not be set by the user, but users can query.
	State *State
	// contains filtered or unexported fields
}

Block represents a set of replated work. It contains a list of sequences that are executed with a configurable amount of concurrency. If a block fails, the workflow will fail. Only one block can be executed at a time.

func (*Block) Defaults

func (b *Block) Defaults()

Defaults sets the default values for the object. For use internally.

func (*Block) Equal

func (b *Block) Equal(other *Block) bool

Equal returns true if the Block objects are equal. Only compares public fields.

func (*Block) GetID

func (b *Block) GetID() uuid.UUID

GetID is a getter for the ID field.

func (*Block) GetPlanID

func (b *Block) GetPlanID() uuid.UUID

GetPlanID returns the Plan ID that the object belongs to.

func (*Block) GetState

func (b *Block) GetState() *State

GetState is a getter for the State settings.

func (*Block) SetID

func (b *Block) SetID(id uuid.UUID)

SetID is a setter for the ID field. This should not be used by the user.

func (*Block) SetPlanID

func (b *Block) SetPlanID(u uuid.UUID)

SetPlanID sets the Plan ID that the object belongs to. This should not be used by the user.

func (*Block) SetState

func (b *Block) SetState(state *State)

SetState is a setter for the State settings.

func (*Block) Type

func (b *Block) Type() ObjectType

Type implements the Object.Type().

type Checks

type Checks struct {
	// ID is a unique identifier for the object. Should not be set by the user.
	ID uuid.UUID
	// Key is a unique identifier within a Plan that the user supplies and can use to reference
	// the checks. Optional.
	Key uuid.UUID
	// Delay is the amount of time to wait before executing the checks. This
	// is only used by continuous checks. Optional. Defaults to 30 seconds.
	Delay time.Duration `json:",format:iso8601"`
	// Actions is a list of actions that are executed in parallel. Any error will
	// cause the workflow to fail. Required.
	Actions []*Action

	// State represents the internal state of the object. Should not be set by the user.
	State *State
	// contains filtered or unexported fields
}

Checks represents a set of actions that are executed before the workflow starts.

func (*Checks) Defaults

func (c *Checks) Defaults()

Defaults sets the default values for the object. For use internally.

func (*Checks) Equal

func (c *Checks) Equal(other *Checks) bool

Equal returns true if the Checks objects are equal. Only compares public fields.

func (*Checks) GetID

func (c *Checks) GetID() uuid.UUID

GetID is a getter for the ID field.

func (*Checks) GetPlanID

func (c *Checks) GetPlanID() uuid.UUID

GetPlanID returns the Plan ID that the object belongs to.

func (*Checks) GetState

func (c *Checks) GetState() *State

GetState is a getter for the State settings.

func (*Checks) SetID

func (c *Checks) SetID(id uuid.UUID)

SetID is a setter for the ID field. This should not be used by the user.

func (*Checks) SetPlanID

func (c *Checks) SetPlanID(u uuid.UUID)

SetPlanID sets the Plan ID that the object belongs to. This should not be used by the user.

func (*Checks) SetState

func (c *Checks) SetState(state *State)

SetState is a setter for the State settings.

func (*Checks) Type

func (c *Checks) Type() ObjectType

Type implements the Object.Type().

type FailureReason

type FailureReason int

FailureReason represents the reason that a workflow failed.

const (
	// FRUnknown represents a failure reason that is unknown.
	// This is the case when a workflow is not in a completed state (a state above 500)
	// or the state is WFCompleted.
	FRUnknown FailureReason = 0 // Unknown
	// FRPreCheck represents a failure reason that occurred during pre-checks.
	FRPreCheck FailureReason = 100 // PreCheck
	// FRBlock represents a failure reason that occurred during a block.
	FRBlock FailureReason = 200 // Block
	// FRPostCheck represents a failure reason that occurred during post-checks.
	FRPostCheck FailureReason = 300 // PostCheck
	// FRContCheck represents a failure reason that occurred during a continuous check.
	FRContCheck FailureReason = 400 // ContCheck
	// FRDeferredCheck represents a failure reason that occurred during a deferred check.
	FRDeferredCheck FailureReason = 450 // DeferredCheck
	// FRStopped represents a failure reason that occurred because the workflow was stopped.
	FRStopped FailureReason = 500 // Stopped
	// FRExceedRecovery represents a failure reason that occurred because the last update for
	// a workflow was too long ago to do a recovery.
	FRExceedRecovery FailureReason = 600 // ExceedRecovery
)

func (FailureReason) String

func (i FailureReason) String() string

type Object

type Object interface {
	// Type returns the type of the object.
	Type() ObjectType
	// contains filtered or unexported methods
}

Object is an interface that all workflow objects must implement.

type ObjectType

type ObjectType int

ObjectType is the type of object.

const (
	// OTUnknown represents an unknown object type. This is
	// an indication of a bug.
	OTUnknown ObjectType = 0
	// OTPlan represents a workflow plan.
	OTPlan ObjectType = 1
	// OTCheck represents a check object.
	OTCheck ObjectType = 2
	// OTBlock represents a Block.
	OTBlock ObjectType = 5
	// OTSequence represents a Sequence.
	OTSequence ObjectType = 6
	// OTAction represents an Action.
	OTAction ObjectType = 7
)

func (ObjectType) String

func (i ObjectType) String() string

type Plan

type Plan struct {
	// ID is a unique identifier for the object. Should not be set by the user.
	ID uuid.UUID
	// Name is the name of the workflow. Required.
	Name string
	// Descr is a human-readable description of the workflow. Required.
	Descr string
	// GroupID is a unique identifier for a group of workflows. This is used to group
	// workflows together for informational purposes. This is not required.
	GroupID uuid.UUID
	// Meta is any type of metadata that the user wants to store with the workflow.
	// This is not used by the workflow engine. Optional.
	Meta []byte
	// BypassChecks are actions that if they succeed will cause the workflow to be skipped.
	// If any gate fails, the workflow will be executed. Optional.
	BypassChecks *Checks
	// PreChecks are actions that are executed before the workflow starts.
	// Any error will cause the workflow to fail. Optional.
	PreChecks *Checks
	// ContChecks are actions that are executed while the workflow is running.
	// Any error will cause the workflow to fail. Optional.
	ContChecks *Checks
	// Checks are actions that are executed after the workflow has completed.
	// Any error will cause the workflow to fail. Optional.
	PostChecks *Checks
	// DeferredChecks are actions that are executed after the workflow has completed.
	// This is executed regardless of Plan success or failure. However, if the
	// Plan is bypassed via BypassChecks, this will not run.
	// Useful for logging and similar operations. Optional.
	DeferredChecks *Checks

	// Blocks is a list of blocks that are executed in sequence.
	// If a block fails, the workflow will fail.
	// Only one block can be executed at a time. Required.
	Blocks []*Block

	// State is the internal state of the object. Should not be set by the user.
	State *State
	// SubmitTime is the time that the object was submitted. This is only
	// set for the Plan object
	SubmitTime time.Time
	// Reason is the reason that the object failed.
	// This will be set to FRUnknown if not in a failed state.
	Reason FailureReason
}

Plan represents a workflow plan that can be executed. This is the main struct that is used to define the workflow.

func (*Plan) Defaults

func (p *Plan) Defaults()

Defaults sets the default values for the object. For use internally.

func (*Plan) Equal

func (p *Plan) Equal(other *Plan) bool

Equal returns true if the Plan objects are equal. Only compares public fields.

func (*Plan) GetID

func (p *Plan) GetID() uuid.UUID

GetID returns the ID of the object.

func (*Plan) GetState

func (p *Plan) GetState() *State

GetStates is a getter for the State settings. This violates Go naming for getters, but this is because we expose State on most objects by the State name (unlike most getter/setters). This is here to enable an interface for getting State on all objects.

func (*Plan) SetID

func (p *Plan) SetID(id uuid.UUID)

SetID sets the ID of the object.

func (*Plan) SetState

func (p *Plan) SetState(state *State)

SetState is a setter for the State settings.

func (*Plan) Type

func (p *Plan) Type() ObjectType

Type implements the Object.Type().

type Sequence

type Sequence struct {
	// ID is a unique identifier for the object. Should not be set by the user.
	ID uuid.UUID
	// Key is a unique identifier within a Plan that the user supplies and can use to reference
	// the sequence. Optional.
	Key uuid.UUID
	// Name is the name of the sequence. Required.
	Name string
	// Descr is a description of the sequence. Required.
	Descr string
	// Actions is a list of actions that are executed in sequence. Any error will cause the workflow to fail. Required.
	Actions []*Action

	// State represents settings that should not be set by the user, but users can query.
	State *State
	// contains filtered or unexported fields
}

Sequence represents a set of Actions that are executed in sequence. Any error will cause the workflow to fail.

func (*Sequence) Defaults

func (s *Sequence) Defaults()

Defaults sets the default values for the object. For use internally.

func (*Sequence) Equal

func (s *Sequence) Equal(other *Sequence) bool

Equal returns true if the Sequence objects are equal. Only compares public fields.

func (*Sequence) GetID

func (s *Sequence) GetID() uuid.UUID

GetID is a getter for the ID field.

func (*Sequence) GetPlanID

func (s *Sequence) GetPlanID() uuid.UUID

GetPlanID returns the Plan ID that the object belongs to.

func (*Sequence) GetState

func (s *Sequence) GetState() *State

GetState is a getter for the State settings.

func (*Sequence) SetID

func (s *Sequence) SetID(id uuid.UUID)

SetID is a setter for the ID field.

func (*Sequence) SetPlanID

func (s *Sequence) SetPlanID(u uuid.UUID)

SetPlanID sets the Plan ID that the object belongs to. This should not be used by the user.

func (*Sequence) SetState

func (s *Sequence) SetState(state *State)

SetState is a setter for the State settings.

func (*Sequence) Type

func (s *Sequence) Type() ObjectType

Type implements the Object.Type().

type State

type State struct {
	// Status is the status of the object.
	Status Status
	// Start is the time that the object was started.
	Start time.Time
	// End is the time that the object was completed.
	End time.Time
	// Etag is a field that may be used internally by storage implementations for concurrency control.
	ETag string
}

State represents the internal state of a workflow object.

func (*State) Duration

func (s *State) Duration() time.Duration

Duration returns the time between Start and End for this object.

func (*State) Equal

func (s *State) Equal(other *State) bool

Equal returns true if the State objects are equal. Only compares public fields.

func (*State) Reset

func (s *State) Reset()

Reset resets the running state of the object. Not for use by users.

type Status

type Status int

Status represents the status of a various workflow objects. Not all objects will have all statuses.

const (
	// NotStarted represents an object that has not started execution.
	NotStarted Status = 0 // NotStarted
	// Running represents an object that is currently running.
	Running Status = 100 // Running
	// Completed represents an object that has completed successfully. For a Plan,
	// this indicates a successful execution, but does not mean that the workflow did not have errors.
	Completed Status = 200 // Completed
	// Failed represents an object that has failed.
	Failed Status = 300 // Failed
	// Stopped represents an object that has been stopped by a user action.
	Stopped Status = 400 // Stopped
)

func (Status) String

func (i Status) String() string

Directories

Path Synopsis
Package builder allows building a workflow Plan sequentially instead of constructing a Plan object manually.
Package builder allows building a workflow Plan sequentially instead of constructing a Plan object manually.
Package context provides both the stdlib context package and functions for managing the context in the SDK.
Package context provides both the stdlib context package and functions for managing the context in the SDK.
Package errors provides an errors package for this service.
Package errors provides an errors package for this service.
Package storage provides the storage interfaces for reading and writing workflow.Plan data.
Package storage provides the storage interfaces for reading and writing workflow.Plan data.
cosmosdb
Package cosmosdb provides a cosmosdb-based storage implementation for workflow.Plan data.
Package cosmosdb provides a cosmosdb-based storage implementation for workflow.Plan data.
noop
Package noop provides a no-op implementation of the storage.Vault interface.
Package noop provides a no-op implementation of the storage.Vault interface.
sqlite
Package sqlite provides a sqlite-based storage implementation for workflow.Plan data.
Package sqlite provides a sqlite-based storage implementation for workflow.Plan data.
utils
clone
Package clone provides advanced cloning for Plans and object contained in Plans.
Package clone provides advanced cloning for Plans and object contained in Plans.
html/internal/embedded
Package embedded provides embedded files for multiple packages.
Package embedded provides embedded files for multiple packages.
html/internal/embedded/reporter
Reporter pvovides a binary file that will read the reports from a sub-directory called "report" and serve them on a web server.
Reporter pvovides a binary file that will read the reports from a sub-directory called "report" and serve them on a web server.
html/reports
Package reports provides a way to render a workflow.Plan to an HTML document with a program that will let you read it.
Package reports provides a way to render a workflow.Plan to an HTML document with a program that will let you read it.
walk
Package walk provides a way to walk a workflow.Plan for all objects under it.
Package walk provides a way to walk a workflow.Plan for all objects under it.

Jump to

Keyboard shortcuts

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