lifecycle

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MPL-2.0 Imports: 6 Imported by: 9

Documentation

Overview

Package lifecycle offers a high-level API for managing Temporal activities' lifecycle in a consistent way across specifications and integrations. It includes activity options and heartbeat. This avoids misconfigured contexts when executing activities from workflows defined in this ecosystem.

It exposes an opiniated way to use activities' contexts. It's primarly designed for internal use but can be leveraged by third-party packages if needed.

Index

Constants

View Source
const LogPoliciesForbidden string = "policies can not be overridden for this integration"

LogPoliciesForbidden is the error log occuring when the input of a workflow tries to override the integration policies whereas it has set its AllowPoliciesOverride to false.

Variables

This section is empty.

Functions

func StartHeartbeat

func StartHeartbeat(ctx context.Context) (context.Context, func())

StartHeartbeat starts a new heartbeat for an activity's context. It returns the populated activity's context with heartbeat along the function to stop the said heartbeat.

Canceling this context releases resources associated with it, so code should call stop as soon as the operations running in this context complete.

Example:

ctx, stop := StartHeartbeat(ctx)
defer stop()

Types

type ActivityPolicy

type ActivityPolicy struct {

	// SingleAttemptTimeout is the maximum time of a single activity execution
	// attempt.
	SingleAttemptTimeout time.Duration `json:"single_timeout,omitempty"`

	// TotalAttemptsTimeout is the total time that a workflow is willing to wait
	// for an activity to complete, including retries.
	TotalAttemptsTimeout time.Duration `json:"total_timeout,omitempty"`

	// HeartbeatTimeout is the activity's hearbeat interval sent to the parent
	// workflow.
	HeartbeatTimeout time.Duration `json:"heartbeat_timeout,omitempty"`

	// RetryPolicy defines the retry policy to apply for the activity.
	RetryPolicy *RetryPolicy `json:"retry,omitempty"`
}

ActivityPolicy is the policies to apply for an activitiy inside an integration's workflow.

func DefaultActivityPolicy

func DefaultActivityPolicy() ActivityPolicy

DefaultActivityPolicy returns the default policies for an activity.

func (ActivityPolicy) MergeWith

func (p ActivityPolicy) MergeWith(input ActivityPolicy) ActivityPolicy

MergeWith merges two policies together.

func (ActivityPolicy) ToContext

func (p ActivityPolicy) ToContext(ctx workflow.Context) workflow.Context

ToContext adds a Temporal activity policy to a workflow's context.

func (ActivityPolicy) ToLocalContext

func (p ActivityPolicy) ToLocalContext(ctx workflow.Context) workflow.Context

ToLocalContext adds a Temporal local activity policy to a workflow's context.

func (ActivityPolicy) ToLocalOptions

func (p ActivityPolicy) ToLocalOptions() workflow.LocalActivityOptions

ToLocalOptions transforms an activity policy to a valid Temporal local activity.

func (ActivityPolicy) ToOptions

func (p ActivityPolicy) ToOptions() workflow.ActivityOptions

ToOptions transforms an activity policy to a valid Temporal activity.

type OnlyOncePolicy

type OnlyOncePolicy struct {

	// HeartbeatTimeout is the activity's hearbeat interval sent to the parent
	// workflow.
	HeartbeatTimeout time.Duration `json:"heartbeat_timeout,omitempty"`
}

OnlyOncePolicy are activity policies that must succeed on their first attempt and don't have retries.

When executing a workflow with an activity that must run only once, it's up to the client to set the workflow timeouts and the following retry policy:

client.StartWorkflowOptions{
  ID:                       "workflow",
  TaskQueue:                "queue",
  WorkflowExecutionTimeout: 10 * time.Second,
  RetryPolicy: &temporal.RetryPolicy{
    MaximumAttempts: 1,
  },
}

func DefaultOnlyOncePolicy

func DefaultOnlyOncePolicy() OnlyOncePolicy

DefaultOnlyOncePolicy returns the default policies for an activity that must run only once.

func (OnlyOncePolicy) MergeWith

func (p OnlyOncePolicy) MergeWith(input OnlyOncePolicy) OnlyOncePolicy

MergeWith merges two policies together.

func (OnlyOncePolicy) ToContext

func (p OnlyOncePolicy) ToContext(ctx workflow.Context) workflow.Context

ToContext adds a Temporal activity policy to a workflow's context.

func (OnlyOncePolicy) ToLocalContext

func (p OnlyOncePolicy) ToLocalContext(ctx workflow.Context) workflow.Context

ToLocalContext adds a Temporal local activity policy to a workflow's context.

func (OnlyOncePolicy) ToLocalOptions

ToLocalOptions transforms an activity policy to a valid Temporal local activity.

func (OnlyOncePolicy) ToOptions

ToOptions transforms an activity policy to a valid Temporal activity.

type RetryPolicy

type RetryPolicy struct {

	// InitialInterval is the backoff interval for the first retry. If
	// BackoffCoefficient is 1.0 then it is used for all retries. If not set or
	// set to 0, a default interval of 5 seconds will be used.
	InitialInterval time.Duration `json:"initial_interval,omitempty"`

	// BackoffCoefficient is used to calculate the next retry backoff interval. The
	// next retry interval is the previous interval multiplied by this coefficient.
	// Must be 1 or larger. Default is 2.0.
	BackoffCoefficient float64 `json:"backoff,omitempty"`

	// MaximumInterval is the maximum backoff interval between retries. Exponential
	// backoff leads to interval increase. This value is the cap of the interval
	// Default is 100x of InitialInterval.
	MaximumInterval time.Duration `json:"maximum_interval,omitempty"`

	// MaximumAttempts is the maximum number of attempts. When exceeded the retries
	// stop even if not expired yet.
	MaximumAttempts int32 `json:"maximum_attempts,omitempty"`
}

RetryPolicy defines the retry policy for an activity.

type Status

type Status string

Status is a custom type defining the status of a workflow or activity.

const StatusFailure Status = "failure"

StatusFailure indicates the workflow or activity has failed.

const StatusStepRollingback Status = "rollingback"

StatusStepRollingback indicates an activity part of a DSL workflow is currently "rollingback".

const StatusStepRunning Status = "running"

StatusStepRunning indicates an activity part of a DSL workflow is currently "running".

const StatusSuccess Status = "success"

StatusSuccess indicates the workflow or activity has succeeded.

func DefaultStatus

func DefaultStatus() Status

DefaultStatus returns the default status of workflows and activities before being run. By default, workflows and activities are StatusFailure.

Jump to

Keyboard shortcuts

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