temporalex

package module
v0.0.0-...-50d906a Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 17 Imported by: 0

README

temporalex

This library creates ergonomic functions around Temporal

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSystemCancellation = errors.New("system cancellation")
	ErrTimeout            = errors.New("timed out")
)

Functions

func DefaultActivityOptions

func DefaultActivityOptions() workflow.ActivityOptions

func DefaultUnwrap

func DefaultUnwrap[T error](appErr *temporal.ApplicationError) error

func DefaultWrap

func DefaultWrap[T error](err error) (error, bool)

func RegisterCustomError

func RegisterCustomError(errType string, unwrapFn UnwrapAppErrorFunc, wrapFn WrapErrorFunc)

RegisterCustomError provides a centralized registry of custom errors that can be unwrapped using UnwrapCustomError

func RegisterCustomErrorDefault

func RegisterCustomErrorDefault[T error](errType string)

func UnwrapCustomError

func UnwrapCustomError(appErr *temporal.ApplicationError) error

UnwrapCustomError unwraps a temporal.ApplicationError into a detailed error This is useful for serializing errors with details other than the error message

func WrapCustomError

func WrapCustomError(err error) error

Types

type Activity

type Activity[TConfig any, TInput any, TResult any] struct {
	Name    string
	Options workflow.ActivityOptions
	Run     ActivityRunFunc[TConfig, TInput, TResult]
	// PostRun executes before completing the activity
	// This function executes inside the registered function of the activity
	// This function is useful for finalizing execution of an activity
	PostRun PostActivityFunc[TResult]
	// HandleResult executes after the activity completes
	// This function executes in the workflow that called the activity
	HandleResult HandleActivityFunc[TInput, TResult]
}

func (Activity[TConfig, TInput, TResult]) Do

func (a Activity[TConfig, TInput, TResult]) Do(wctx workflow.Context, input TInput) (TResult, error)

func (Activity[TConfig, TInput, TResult]) DoLocal

func (a Activity[TConfig, TInput, TResult]) DoLocal(wctx workflow.Context, input TInput) (TResult, error)

func (Activity[TConfig, TInput, TResult]) Register

func (a Activity[TConfig, TInput, TResult]) Register(cfg TConfig, registry worker.Registry)

type ActivityRunFunc

type ActivityRunFunc[TConfig any, TInput any, TResult any] func(ctx context.Context, cfg TConfig, input TInput) (TResult, error)

type ActivityTestScaffold

type ActivityTestScaffold struct {
	testsuite.WorkflowTestSuite
	Env *testsuite.TestActivityEnvironment
	T   *testing.T
}

func (ActivityTestScaffold) RegisterActivity

func (a ActivityTestScaffold) RegisterActivity(act interface{})

func (ActivityTestScaffold) RegisterActivityWithOptions

func (a ActivityTestScaffold) RegisterActivityWithOptions(act interface{}, options activity.RegisterOptions)

func (ActivityTestScaffold) RegisterWorkflow

func (a ActivityTestScaffold) RegisterWorkflow(w interface{})

func (ActivityTestScaffold) RegisterWorkflowWithOptions

func (a ActivityTestScaffold) RegisterWorkflowWithOptions(w interface{}, options workflow.RegisterOptions)

type ErrorWrapper

type ErrorWrapper interface {
	WrapError() error
}

type ExternalActivity

type ExternalActivity[TInput any, TResult any] struct {
	Name      string
	TaskQueue string
	Options   workflow.ActivityOptions
	// HandleResult executes after the activity completes
	// This function executes in the workflow that called the activity
	HandleResult HandleActivityFunc[TInput, TResult]
}

func (ExternalActivity[TInput, TResult]) Do

func (a ExternalActivity[TInput, TResult]) Do(wctx workflow.Context, input TInput) (TResult, error)

type ExternalWorkflow

type ExternalWorkflow[TInput WorkflowInput, TResult any] struct {
	Name              string
	TaskQueue         string
	ParentClosePolicy enums.ParentClosePolicy
	// HandleResult executes after the child workflow completes
	// This function executes in the parent workflow that called the executing child workflow
	HandleResult OnResolvedFunc[TResult]
}

func (ExternalWorkflow[TInput, TResult]) Do

func (w ExternalWorkflow[TInput, TResult]) Do(ctx context.Context, temporalClient client.Client, input TInput) (TResult, error)

func (ExternalWorkflow[TInput, TResult]) DoAsync

func (w ExternalWorkflow[TInput, TResult]) DoAsync(ctx context.Context, temporalClient client.Client, input TInput) (client.WorkflowRun, error)

func (ExternalWorkflow[TInput, TResult]) DoChild

func (w ExternalWorkflow[TInput, TResult]) DoChild(wctx workflow.Context, input TInput) (TResult, error)

func (ExternalWorkflow[TInput, TResult]) DoChildAsync

func (w ExternalWorkflow[TInput, TResult]) DoChildAsync(wctx workflow.Context, input TInput) *TypedFuture[TResult]

type FakeInput

type FakeInput struct {
	TemporalWorkflowId string
}

func (FakeInput) GetTemporalWorkflowId

func (f FakeInput) GetTemporalWorkflowId(name string) string

func (FakeInput) SearchAttributes

func (f FakeInput) SearchAttributes() []temporal.SearchAttributeUpdate

func (FakeInput) SpanAttributes

func (f FakeInput) SpanAttributes() []attribute.KeyValue

type HandleActivityFunc

type HandleActivityFunc[TInput any, TResult any] func(wctx workflow.Context, input TInput, result TResult, err error) (TResult, error)

type HandleWorkflowFunc

type HandleWorkflowFunc[TInput any, TResult any] func(wctx workflow.Context, ctx context.Context, input TInput, result TResult, err error) (TResult, error)

type OnResolvedFunc

type OnResolvedFunc[T any] func(wctx workflow.Context, result T, err error) (T, error)

type PanicError

type PanicError struct {
	Message    string `json:"message"`
	StackTrace string `json:"stackTrace"`
}

func (PanicError) Error

func (e PanicError) Error() string

type PostActivityFunc

type PostActivityFunc[TResult any] func(ctx context.Context, result TResult, err error) (TResult, error)

type PostRunFunc

type PostRunFunc[TInput any, TResult any] func(wctx workflow.Context, input TInput, result TResult, err error) (TResult, error)

type Registrar

type Registrar[TConfig any] interface {
	Register(cfg TConfig, registry worker.Registry)
}

type RunFunc

type RunFunc[TConfig any, TInput any, TResult any] func(wctx workflow.Context, ctx context.Context, cfg TConfig, input TInput) (TResult, error)

type TypedFuture

type TypedFuture[T any] struct {
	Result T
	Err    error
	// contains filtered or unexported fields
}

func NewFuture

func NewFuture[T any](future workflow.Future, onResolved OnResolvedFunc[T]) *TypedFuture[T]

func NewResolvedFuture

func NewResolvedFuture[T any](wctx workflow.Context, result T, err error) *TypedFuture[T]

func (*TypedFuture[T]) AddToSelector

func (f *TypedFuture[T]) AddToSelector(wctx workflow.Context, selector workflow.Selector, fns ...func(f TypedFuture[T]) T)

func (*TypedFuture[T]) Get

func (f *TypedFuture[T]) Get(wctx workflow.Context, ptr any) error

func (*TypedFuture[T]) GetTyped

func (f *TypedFuture[T]) GetTyped(wctx workflow.Context) (T, error)

func (*TypedFuture[T]) IsReady

func (f *TypedFuture[T]) IsReady() bool

type UnwrapAppErrorFunc

type UnwrapAppErrorFunc func(appErr *temporal.ApplicationError) error

type UnwrapErrType

type UnwrapErrType string
const (
	UnwrapErrTypeNone         UnwrapErrType = ""
	UnwrapErrTypeFailure      UnwrapErrType = "failure"
	UnwrapErrTypePanic        UnwrapErrType = "panic"
	UnwrapErrTypeCancellation UnwrapErrType = "cancellation"
	UnwrapErrTypeTimeout      UnwrapErrType = "timeout"
)

func UnwrapError

func UnwrapError(inputErr error) (UnwrapErrType, string, error)

UnwrapError takes an error from a workflow or activity and unwraps the Temporal skeleton to leave the base error This utilizes UnwrapCustomError to extract the strongly-typed error across workflow/activity boundaries

type Workflow

type Workflow[TConfig any, TInput WorkflowInput, TResult any] struct {
	Name              string
	TaskQueue         string
	ParentClosePolicy enums.ParentClosePolicy
	Activities        []Registrar[TConfig]
	Run               RunFunc[TConfig, TInput, TResult]
	// PostRun executes before completing the child workflow
	// This function executes inside the registered function of the child workflow
	// This function is useful for finalizing execution of a child workflow
	PostRun PostRunFunc[TInput, TResult]
	// HandleResult executes after the child workflow completes
	// This function executes in the parent workflow that called the executing child workflow
	HandleResult HandleWorkflowFunc[TInput, TResult]
}

func (Workflow[TConfig, TInput, TResult]) Do

func (w Workflow[TConfig, TInput, TResult]) Do(ctx context.Context, temporalClient client.Client, input TInput) (TResult, error)

func (Workflow[TConfig, TInput, TResult]) DoAsync

func (w Workflow[TConfig, TInput, TResult]) DoAsync(ctx context.Context, temporalClient client.Client, input TInput) (client.WorkflowRun, error)

func (Workflow[TConfig, TInput, TResult]) DoChild

func (w Workflow[TConfig, TInput, TResult]) DoChild(wctx workflow.Context, ctx context.Context, input TInput) (TResult, error)

func (Workflow[TConfig, TInput, TResult]) DoChildAsync

func (w Workflow[TConfig, TInput, TResult]) DoChildAsync(wctx workflow.Context, ctx context.Context, input TInput) *TypedFuture[TResult]

func (Workflow[TConfig, TInput, TResult]) Register

func (w Workflow[TConfig, TInput, TResult]) Register(cfg TConfig, registry worker.Registry)

type WorkflowInput

type WorkflowInput interface {
	GetTemporalWorkflowId(name string) string
	SearchAttributes() []temporal.SearchAttributeUpdate
	SpanAttributes() []attribute.KeyValue
}

type WorkflowTestScaffold

type WorkflowTestScaffold struct {
	testsuite.WorkflowTestSuite
	Env *testsuite.TestWorkflowEnvironment
	T   *testing.T
}

func (WorkflowTestScaffold) RegisterActivity

func (a WorkflowTestScaffold) RegisterActivity(act interface{})

func (WorkflowTestScaffold) RegisterActivityWithOptions

func (a WorkflowTestScaffold) RegisterActivityWithOptions(act interface{}, options activity.RegisterOptions)

func (WorkflowTestScaffold) RegisterWorkflow

func (a WorkflowTestScaffold) RegisterWorkflow(w interface{})

func (WorkflowTestScaffold) RegisterWorkflowWithOptions

func (a WorkflowTestScaffold) RegisterWorkflowWithOptions(w interface{}, options workflow.RegisterOptions)

type WrapErrorFunc

type WrapErrorFunc func(err error) (error, bool)

Jump to

Keyboard shortcuts

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