Documentation ¶
Index ¶
- 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)
- type Activity
- type ActivityOptions
- 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 ExecuteActivity[TResult any](ctx Context, options ActivityOptions, activity Activity, args ...any) Future[TResult]
- func ScheduleTimer(ctx Context, delay time.Duration) 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 RetryOptions
- type SelectCase
- type Span
- type SubWorkflowOptions
- type WaitGroup
- type Workflow
- type WorkflowTracer
Constants ¶
This section is empty.
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 ¶ added in v0.15.0
ContinueAsNew restarts the current workflow with the given arguments.
func NewError ¶ added in v0.16.0
NewError wraps the given error into a workflow error which will be automatically retried
func NewPermanentError ¶ added in v0.16.0
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.
Types ¶
type ActivityOptions ¶
type ActivityOptions struct { // RetryOptions defines how to retry the activity in case of failure. RetryOptions RetryOptions }
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() }
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 ¶ added in v0.13.0
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 ¶ added in v0.14.0
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 ¶ added in v0.16.0
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 ExecuteActivity ¶
func ExecuteActivity[TResult any](ctx Context, options ActivityOptions, activity Activity, args ...any) Future[TResult]
ExecuteActivity schedules the given activity to be executed
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 ¶ added in v0.5.0
SignalWorkflow sends a signal to another running workflow instance.
func WithRetries ¶ added in v0.16.0
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 ¶ added in v0.0.3
WorkflowInstance returns the current workflow instance.
type Metadata ¶ added in v0.4.0
type Metadata = metadata.WorkflowMetadata
Metadata represents the metadata of a workflow instance.
type PanicError ¶ added in v0.16.0
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 RetryOptions RetryOptions }
type WaitGroup ¶ added in v0.0.3
func NewWaitGroup ¶ added in v0.0.3
func NewWaitGroup() WaitGroup
NewWaitGroup creates a new WaitGroup instance.
type WorkflowTracer ¶ added in v0.4.1
type WorkflowTracer struct {
// contains filtered or unexported fields
}
func Tracer ¶ added in v0.4.1
func Tracer(ctx Context) *WorkflowTracer
Tracer creates a the workflow tracer.
func (*WorkflowTracer) Start ¶ added in v0.4.1
func (wt *WorkflowTracer) Start(ctx Context, name string, opts ...trace.SpanStartOption) (Context, Span)
Start starts a new span.