workflow

package
v0.0.0-...-928aca3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 10 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 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
	// 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
	// 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) Clone

func (a *Action) Clone() *Action

Clone clones an Action with no ID, no Attempts and no State.

func (*Action) Defaults

func (a *Action) Defaults()

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

func (*Action) GetID

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

GetID is a getter for the ID field.

func (*Action) GetState

func (a *Action) GetState() *State

GetState is a getter for the State settings.

func (*Action) HasRegister

func (a *Action) HasRegister() bool

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) SetRegister

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

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

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.

type Block

type Block 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 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
	// ExitDelay is the amount of time to wait after the block has completed. This defaults to 0.
	ExitDelay time.Duration

	// 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

	// 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
}

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) Clone

func (b *Block) Clone() *Block

Clone makes a copy of the block, but without an ID or State. All checks and sequences are cloned acccording to their Clone() method.

func (*Block) Defaults

func (b *Block) Defaults()

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

func (*Block) GetID

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

GetID is a getter for the ID field.

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) 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
	// 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
	// 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
}

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

func (*Checks) Clone

func (c *Checks) Clone() *Checks

Clone clones the Checks object. This does not copy the ID or the State object. All actions are cloned according to their Clone() method.

func (*Checks) Defaults

func (c *Checks) Defaults()

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

func (*Checks) GetID

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

GetID is a getter for the ID field.

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) 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
	// FRStopped represents a failure reason that occurred because the workflow was stopped.
	FRStopped FailureReason = 500 // Stopped
)

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
	// A 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

	// 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

	// 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) Clone

func (p *Plan) Clone() *Plan

Clone clones a plan with no ID, State, SubmitTime or Reason. It also clones all of the sub-objects according to their Clone() method.

func (*Plan) Defaults

func (p *Plan) Defaults()

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

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
	// 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
}

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

func (*Sequence) Clone

func (s *Sequence) Clone() *Sequence

Clone clones an Sequence with no ID and no State. Also clones all the Actions following the cloning rules of the Action.Clone() method.

func (*Sequence) Defaults

func (s *Sequence) Defaults()

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

func (*Sequence) GetID

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

GetID is a getter for the ID field.

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) 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
}

State represents the internal state of a workflow object.

func (*State) Clone

func (s *State) Clone() *State

Clone returns a copy of the state. This is not used by any object Clone method, but can be used in testing.

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 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.
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
html/internal/embeded
Package embeded provides embeded files for multiple packages.
Package embeded provides embeded files for multiple packages.
html/internal/embeded/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