Documentation
¶
Index ¶
- Constants
- Variables
- func CanRetry(err error) bool
- func ContinueAsNew(ctx Context, args ...any) error
- func Go(ctx Context, f func(ctx Context))
- func Logger(ctx Context) *slog.Logger
- func NewError(err error) error
- func NewPermanentError(err error) error
- func Now(ctx Context) time.Time
- func Replaying(ctx Context) bool
- func Select(ctx Context, cases ...SelectCase)
- func Sleep(ctx Context, d time.Duration) error
- func WithCancel(parent Context) (ctx Context, cancel CancelFunc)
- func WithCancelCause(parent Context) (ctx Context, cancel CancelCauseFunc)
- func WithTimerName(name string) timerOption
- type Activity
- type ActivityFunc0
- type ActivityFunc1
- type ActivityFunc2
- type ActivityFunc3
- type ActivityFuncNoResult0
- type ActivityFuncNoResult1
- type ActivityFuncNoResult2
- type ActivityFuncNoResult3
- type ActivityOptions
- type CancelCauseFunc
- type CancelFunc
- type Channel
- type Context
- type ContextPropagator
- type Error
- type Future
- func CreateSubWorkflowInstance[TResult any](ctx Context, options SubWorkflowOptions, workflow Workflow, args ...any) Future[TResult]
- func CreateTypedSubWorkflow0[TResult any](ctx Context, options SubWorkflowOptions, wf WorkflowFunc0[TResult]) Future[TResult]
- func CreateTypedSubWorkflow1[TInput, TResult any](ctx Context, options SubWorkflowOptions, wf WorkflowFunc1[TInput, TResult], ...) Future[TResult]
- func CreateTypedSubWorkflow2[TInput1, TInput2, TResult any](ctx Context, options SubWorkflowOptions, ...) Future[TResult]
- func CreateTypedSubWorkflow3[TInput1, TInput2, TInput3, TResult any](ctx Context, options SubWorkflowOptions, ...) Future[TResult]
- func CreateTypedSubWorkflowNoResult0(ctx Context, options SubWorkflowOptions, wf WorkflowFuncNoResult0) Future[any]
- func CreateTypedSubWorkflowNoResult1[TInput any](ctx Context, options SubWorkflowOptions, wf WorkflowFuncNoResult1[TInput], ...) Future[any]
- func CreateTypedSubWorkflowNoResult2[TInput1, TInput2 any](ctx Context, options SubWorkflowOptions, ...) Future[any]
- func CreateTypedSubWorkflowNoResult3[TInput1, TInput2, TInput3 any](ctx Context, options SubWorkflowOptions, ...) Future[any]
- func ExecuteActivity[TResult any](ctx Context, options ActivityOptions, activity Activity, args ...any) Future[TResult]
- func ExecuteTypedActivity0[TResult any](ctx Context, options ActivityOptions, activity ActivityFunc0[TResult]) Future[TResult]
- func ExecuteTypedActivity1[TInput, TResult any](ctx Context, options ActivityOptions, activity ActivityFunc1[TInput, TResult], ...) Future[TResult]
- func ExecuteTypedActivity2[TInput1, TInput2, TResult any](ctx Context, options ActivityOptions, ...) Future[TResult]
- func ExecuteTypedActivity3[TInput1, TInput2, TInput3, TResult any](ctx Context, options ActivityOptions, ...) Future[TResult]
- func ExecuteTypedActivityNoResult0(ctx Context, options ActivityOptions, activity ActivityFuncNoResult0) Future[any]
- func ExecuteTypedActivityNoResult1[TInput any](ctx Context, options ActivityOptions, activity ActivityFuncNoResult1[TInput], ...) Future[any]
- func ExecuteTypedActivityNoResult2[TInput1, TInput2 any](ctx Context, options ActivityOptions, ...) Future[any]
- func ExecuteTypedActivityNoResult3[TInput1, TInput2, TInput3 any](ctx Context, options ActivityOptions, ...) Future[any]
- func ScheduleTimer(ctx Context, delay time.Duration, opts ...timerOption) Future[any]
- func SideEffect[TResult any](ctx Context, f func(ctx Context) TResult) Future[TResult]
- func SignalWorkflow[T any](ctx Context, instanceID string, name string, arg T) Future[any]
- func WithRetries[T any](ctx Context, retryOptions RetryOptions, ...) Future[T]
- type Instance
- type Metadata
- type PanicError
- type Queue
- type RetryOptions
- type SelectCase
- type Span
- type SubWorkflowOptions
- type WaitGroup
- type Workflow
- type WorkflowFunc0
- type WorkflowFunc1
- type WorkflowFunc2
- type WorkflowFunc3
- type WorkflowFuncNoResult0
- type WorkflowFuncNoResult1
- type WorkflowFuncNoResult2
- type WorkflowFuncNoResult3
- type WorkflowInstanceExecutionDetails
- type WorkflowTracer
Constants ¶
const (
QueueDefault = core.QueueDefault
)
Variables ¶
var ( DefaultSubWorkflowRetryOptions = RetryOptions{ MaxAttempts: 1, } DefaultSubWorkflowOptions = SubWorkflowOptions{ RetryOptions: DefaultSubWorkflowRetryOptions, } )
var Canceled = sync.Canceled
var DefaultActivityOptions = ActivityOptions{ RetryOptions: DefaultRetryOptions, }
var DefaultRetryOptions = RetryOptions{
MaxAttempts: 3,
BackoffCoefficient: 1,
}
Functions ¶
func ContinueAsNew ¶
ContinueAsNew restarts the current workflow with the given arguments.
func NewError ¶
NewError wraps the given error into a workflow error which will be automatically retried
func NewPermanentError ¶
NewPermanentError wraps the given error into a workflow error which will not be automatically retried
func Select ¶
func Select(ctx Context, cases ...SelectCase)
Select is the workflow-save equivalent of the select statement.
func WithCancel ¶
func WithCancel(parent Context) (ctx Context, cancel CancelFunc)
WithCancel returns a copy of parent with a new Done channel. The returned context's Done channel is closed when the returned cancel function is called or when the parent context's Done channel is closed, whichever happens first.
Canceling this context releases resources associated with it, so code should call cancel as soon as the operations running in this Context complete.
func WithCancelCause ¶
func WithCancelCause(parent Context) (ctx Context, cancel CancelCauseFunc)
WithCancelCause behaves like WithCancel but returns a CancelCauseFunc instead of a CancelFunc. Calling cancel with a non-nil error (the "cause") records that error in ctx; it can then be retrieved using Cause(ctx). Calling cancel with nil sets the cause to Canceled.
Example use:
ctx, cancel := context.WithCancelCause(parent) cancel(myError) ctx.Err() // returns context.Canceled context.Cause(ctx) // returns myError
func WithTimerName ¶
func WithTimerName(name string) timerOption
Types ¶
type ActivityFunc0 ¶
ActivityFunc0 is an activity function with no input parameters.
type ActivityFunc1 ¶
ActivityFunc1 is an activity function with one input parameter.
type ActivityFunc2 ¶
type ActivityFunc2[TInput1, TInput2, TResult any] func(context.Context, TInput1, TInput2) (TResult, error)
ActivityFunc2 is an activity function with two input parameters.
type ActivityFunc3 ¶
type ActivityFunc3[TInput1, TInput2, TInput3, TResult any] func(context.Context, TInput1, TInput2, TInput3) (TResult, error)
ActivityFunc3 is an activity function with three input parameters.
type ActivityFuncNoResult0 ¶
ActivityFuncNoResult0 is an activity function with no input parameters that returns only an error.
type ActivityFuncNoResult1 ¶
ActivityFuncNoResult1 is an activity function with one input parameter that returns only an error.
type ActivityFuncNoResult2 ¶
ActivityFuncNoResult2 is an activity function with two input parameters that returns only an error.
type ActivityFuncNoResult3 ¶
type ActivityFuncNoResult3[TInput1, TInput2, TInput3 any] func(context.Context, TInput1, TInput2, TInput3) error
ActivityFuncNoResult3 is an activity function with three input parameters that returns only an error.
type ActivityOptions ¶
type ActivityOptions struct {
// Queue defines the activity queue this activity will be delivered to. By default, this inherits
// the queue from the workflow instance.
Queue core.Queue
// RetryOptions defines how to retry the activity in case of failure.
RetryOptions RetryOptions
}
type CancelCauseFunc ¶
type CancelCauseFunc = sync.CancelCauseFunc
A CancelCauseFunc behaves like a CancelFunc but additionally sets the cancellation cause. This cause can be retrieved by calling [Cause] on the canceled Context or on any of its derived Contexts.
If the context has already been canceled, CancelCauseFunc does not set the cause. For example, if childContext is derived from parentContext:
- if parentContext is canceled with cause1 before childContext is canceled with cause2, then Cause(parentContext) == Cause(childContext) == cause1
- if childContext is canceled with cause2 before parentContext is canceled with cause1, then Cause(parentContext) == cause1 and Cause(childContext) == cause2
type CancelFunc ¶
type CancelFunc = sync.CancelFunc
type Channel ¶
type Channel[T any] interface { // Send sends a value to the channel. If the channel is closed, this will panic. Send(ctx Context, v T) // SendNonblocking sends a value to the channel. This call is non-blocking and will return whether the // value could be sent. If the channel is closed, this will panic SendNonblocking(v T) (ok bool) // Receive receives a value from the channel. Receive(ctx Context) (v T, ok bool) // ReceiveNonBlocking tries to receives a value from the channel. This call is non-blocking and will return // whether the value could be returned. ReceiveNonBlocking() (v T, ok bool) // Close closes the channel. This will cause all future send operations to panic. Close() // Len returns the number of elements currently in the channel. Len() int }
func NewBufferedChannel ¶
NewBufferedChannel creates a new buffered channel with the given size.
type Context ¶
func NewDisconnectedContext ¶
NewDisconnectedContext creates a new context that is disconnected from any parent context.
func WithValue ¶
WithValue returns a copy of parent in which the value associated with key is val.
Use context Values only for request-scoped data that transits processes and APIs, not for passing optional parameters to functions.
The provided key must be comparable and should not be of type string or any other built-in type to avoid collisions between packages using context. Users of WithValue should define their own types for keys. To avoid allocating when assigning to an interface{}, context keys often have concrete type struct{}. Alternatively, exported context key variables' static type should be a pointer or interface.
type ContextPropagator ¶
type ContextPropagator interface {
// Inject injects values from context into metadata
Inject(context.Context, *Metadata) error
// Extract extracts values from metadata into context
Extract(context.Context, *Metadata) (context.Context, error)
// InjectFromWorkflow injects values from the workflow context into metadata
InjectFromWorkflow(Context, *Metadata) error
// ExtractToWorkflow extracts values from metadata into a workflow context
ExtractToWorkflow(Context, *Metadata) (Context, error)
}
type Error ¶
type Error = workflowerrors.Error
type Future ¶
type Future[T any] interface { // Get returns the value if set, blocks otherwise Get(ctx Context) (T, error) }
func CreateSubWorkflowInstance ¶
func CreateSubWorkflowInstance[TResult any](ctx Context, options SubWorkflowOptions, workflow Workflow, args ...any) Future[TResult]
CreateSubWorkflowInstance creates a new sub-workflow instance of the given workflow.
func CreateTypedSubWorkflow0 ¶
func CreateTypedSubWorkflow0[TResult any](ctx Context, options SubWorkflowOptions, wf WorkflowFunc0[TResult]) Future[TResult]
CreateTypedSubWorkflow0 creates a sub-workflow with no input parameters (type-safe).
func CreateTypedSubWorkflow1 ¶
func CreateTypedSubWorkflow1[TInput, TResult any](ctx Context, options SubWorkflowOptions, wf WorkflowFunc1[TInput, TResult], input TInput) Future[TResult]
CreateTypedSubWorkflow1 creates a sub-workflow with one input parameter (type-safe).
func CreateTypedSubWorkflow2 ¶
func CreateTypedSubWorkflow2[TInput1, TInput2, TResult any](ctx Context, options SubWorkflowOptions, wf WorkflowFunc2[TInput1, TInput2, TResult], input1 TInput1, input2 TInput2) Future[TResult]
CreateTypedSubWorkflow2 creates a sub-workflow with two input parameters (type-safe).
func CreateTypedSubWorkflow3 ¶
func CreateTypedSubWorkflow3[TInput1, TInput2, TInput3, TResult any](ctx Context, options SubWorkflowOptions, wf WorkflowFunc3[TInput1, TInput2, TInput3, TResult], input1 TInput1, input2 TInput2, input3 TInput3) Future[TResult]
CreateTypedSubWorkflow3 creates a sub-workflow with three input parameters (type-safe).
func CreateTypedSubWorkflowNoResult0 ¶
func CreateTypedSubWorkflowNoResult0(ctx Context, options SubWorkflowOptions, wf WorkflowFuncNoResult0) Future[any]
CreateTypedSubWorkflowNoResult0 creates a sub-workflow with no input parameters that returns only an error (type-safe).
func CreateTypedSubWorkflowNoResult1 ¶
func CreateTypedSubWorkflowNoResult1[TInput any](ctx Context, options SubWorkflowOptions, wf WorkflowFuncNoResult1[TInput], input TInput) Future[any]
CreateTypedSubWorkflowNoResult1 creates a sub-workflow with one input parameter that returns only an error (type-safe).
func CreateTypedSubWorkflowNoResult2 ¶
func CreateTypedSubWorkflowNoResult2[TInput1, TInput2 any](ctx Context, options SubWorkflowOptions, wf WorkflowFuncNoResult2[TInput1, TInput2], input1 TInput1, input2 TInput2) Future[any]
CreateTypedSubWorkflowNoResult2 creates a sub-workflow with two input parameters that returns only an error (type-safe).
func CreateTypedSubWorkflowNoResult3 ¶
func CreateTypedSubWorkflowNoResult3[TInput1, TInput2, TInput3 any](ctx Context, options SubWorkflowOptions, wf WorkflowFuncNoResult3[TInput1, TInput2, TInput3], input1 TInput1, input2 TInput2, input3 TInput3) Future[any]
CreateTypedSubWorkflowNoResult3 creates a sub-workflow with three input parameters that returns only an error (type-safe).
func ExecuteActivity ¶
func ExecuteActivity[TResult any](ctx Context, options ActivityOptions, activity Activity, args ...any) Future[TResult]
ExecuteActivity schedules the given activity to be executed
func ExecuteTypedActivity0 ¶
func ExecuteTypedActivity0[TResult any](ctx Context, options ActivityOptions, activity ActivityFunc0[TResult]) Future[TResult]
ExecuteTypedActivity0 schedules an activity with no input parameters (type-safe).
func ExecuteTypedActivity1 ¶
func ExecuteTypedActivity1[TInput, TResult any](ctx Context, options ActivityOptions, activity ActivityFunc1[TInput, TResult], input TInput) Future[TResult]
ExecuteTypedActivity1 schedules an activity with one input parameter (type-safe).
func ExecuteTypedActivity2 ¶
func ExecuteTypedActivity2[TInput1, TInput2, TResult any](ctx Context, options ActivityOptions, activity ActivityFunc2[TInput1, TInput2, TResult], input1 TInput1, input2 TInput2) Future[TResult]
ExecuteTypedActivity2 schedules an activity with two input parameters (type-safe).
func ExecuteTypedActivity3 ¶
func ExecuteTypedActivity3[TInput1, TInput2, TInput3, TResult any](ctx Context, options ActivityOptions, activity ActivityFunc3[TInput1, TInput2, TInput3, TResult], input1 TInput1, input2 TInput2, input3 TInput3) Future[TResult]
ExecuteTypedActivity3 schedules an activity with three input parameters (type-safe).
func ExecuteTypedActivityNoResult0 ¶
func ExecuteTypedActivityNoResult0(ctx Context, options ActivityOptions, activity ActivityFuncNoResult0) Future[any]
ExecuteTypedActivityNoResult0 schedules an activity with no input parameters that returns only an error (type-safe).
func ExecuteTypedActivityNoResult1 ¶
func ExecuteTypedActivityNoResult1[TInput any](ctx Context, options ActivityOptions, activity ActivityFuncNoResult1[TInput], input TInput) Future[any]
ExecuteTypedActivityNoResult1 schedules an activity with one input parameter that returns only an error (type-safe).
func ExecuteTypedActivityNoResult2 ¶
func ExecuteTypedActivityNoResult2[TInput1, TInput2 any](ctx Context, options ActivityOptions, activity ActivityFuncNoResult2[TInput1, TInput2], input1 TInput1, input2 TInput2) Future[any]
ExecuteTypedActivityNoResult2 schedules an activity with two input parameters that returns only an error (type-safe).
func ExecuteTypedActivityNoResult3 ¶
func ExecuteTypedActivityNoResult3[TInput1, TInput2, TInput3 any](ctx Context, options ActivityOptions, activity ActivityFuncNoResult3[TInput1, TInput2, TInput3], input1 TInput1, input2 TInput2, input3 TInput3) Future[any]
ExecuteTypedActivityNoResult3 schedules an activity with three input parameters that returns only an error (type-safe).
func ScheduleTimer ¶
ScheduleTimer schedules a timer to fire after the given delay.
func SideEffect ¶
SideEffect executes the given function and returns a future that will be resolved with the result of the function.
In contrast to Activities, SideEffects are executed inline with the workflow code. They should only be used for short and inexpensive operations. For longer operations, consider using an Activity.
func SignalWorkflow ¶
SignalWorkflow sends a signal to another running workflow instance.
func WithRetries ¶
func WithRetries[T any](ctx Context, retryOptions RetryOptions, fn func(ctx Context, attempt int) Future[T]) Future[T]
WithRetries executes the given function with retries.
type Instance ¶
type Instance = core.WorkflowInstance
Instance represents a workflow instance.
func WorkflowInstance ¶
WorkflowInstance returns the current workflow instance.
type Metadata ¶
type Metadata = metadata.WorkflowMetadata
Metadata represents the metadata of a workflow instance.
type PanicError ¶
type PanicError = workflowerrors.PanicError
type RetryOptions ¶
type RetryOptions struct {
// Maximum number of times to retry
MaxAttempts int
// Time to wait before first retry
FirstRetryInterval time.Duration
// Maximum delay for any individual retry attempt
MaxRetryInterval time.Duration
// Coeffecient for calculation the next retry delay
BackoffCoefficient float64
// Timeout after which retries are aborted
RetryTimeout time.Duration
}
type SelectCase ¶
type SelectCase = sync.SelectCase
func Await ¶
func Await[T any](f Future[T], handler func(Context, Future[T])) SelectCase
Await calls the provided handler when the given future is ready.
func Default ¶
func Default(handler func(Context)) SelectCase
Default calls the provided handler if none of the other cases match.
func Receive ¶
func Receive[T any](c Channel[T], handler func(ctx Context, v T, ok bool)) SelectCase
Receive calls the provided handler if the given channel can receive a value. The handler receives the received value, and the ok flag indicating whether the value was received or the channel was closed.
type SubWorkflowOptions ¶
type SubWorkflowOptions struct {
InstanceID string
// Queue to use for the sub-workflow, if not set, the queue of the calling workflow will be used.
Queue Queue
RetryOptions RetryOptions
}
type WorkflowFunc0 ¶
WorkflowFunc0 is a workflow function with no input parameters.
type WorkflowFunc1 ¶
WorkflowFunc1 is a workflow function with one input parameter.
type WorkflowFunc2 ¶
WorkflowFunc2 is a workflow function with two input parameters.
type WorkflowFunc3 ¶
type WorkflowFunc3[TInput1, TInput2, TInput3, TResult any] func(Context, TInput1, TInput2, TInput3) (TResult, error)
WorkflowFunc3 is a workflow function with three input parameters.
type WorkflowFuncNoResult0 ¶
WorkflowFuncNoResult0 is a workflow function with no input parameters that returns only an error.
type WorkflowFuncNoResult1 ¶
WorkflowFuncNoResult1 is a workflow function with one input parameter that returns only an error.
type WorkflowFuncNoResult2 ¶
WorkflowFuncNoResult2 is a workflow function with two input parameters that returns only an error.
type WorkflowFuncNoResult3 ¶
type WorkflowFuncNoResult3[TInput1, TInput2, TInput3 any] func(Context, TInput1, TInput2, TInput3) error
WorkflowFuncNoResult3 is a workflow function with three input parameters that returns only an error.
type WorkflowInstanceExecutionDetails ¶
type WorkflowInstanceExecutionDetails struct {
// HistoryLength is the number of events in the workflow history at the current point in execution.
// This value increases as the workflow executes and generates new events.
HistoryLength int64
}
WorkflowInstanceExecutionDetails contains information about the current workflow execution.
func InstanceExecutionDetails ¶
func InstanceExecutionDetails(ctx Context) WorkflowInstanceExecutionDetails
InstanceExecutionDetails returns information about the current workflow execution.
type WorkflowTracer ¶
type WorkflowTracer struct {
}
func (*WorkflowTracer) Start ¶
func (wt *WorkflowTracer) Start(ctx Context, name string, opts ...trace.SpanStartOption) (Context, Span)
Start starts a new span.