activity

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MIT Imports: 4 Imported by: 108

Documentation

Overview

Package activity contains functions and types used to implement Cadence activities.

Index

Constants

This section is empty.

Variables

ErrResultPending is returned from activity's implementation to indicate the activity is not completed when activity method returns. Activity needs to be completed by Client.CompleteActivity() separately. For example, if an activity require human interaction (like approve an expense report), the activity could return ErrResultPending which indicate the activity is not done yet. Then, when the waited human action happened, it needs to trigger something that could report the activity completed event to cadence server via Client.CompleteActivity() API.

Functions

func GetLogger

func GetLogger(ctx context.Context) *zap.Logger

GetLogger returns a logger that can be used in activity

func GetMetricsScope

func GetMetricsScope(ctx context.Context) tally.Scope

GetMetricsScope returns a metrics scope that can be used in activity

func RecordHeartbeat

func RecordHeartbeat(ctx context.Context, details ...interface{})

RecordHeartbeat sends heartbeat for the currently executing activity If the activity is either cancelled (or) workflow/activity doesn't exist then we would cancel the context with error context.Canceled.

TODO: we don't have a way to distinguish between the two cases when context is cancelled because
context doesn't support overriding value of ctx.Error.
TODO: Implement automatic heartbeating with cancellation through ctx.

details - the details that you provided here can be seen in the workflow when it receives TimeoutError, you can check error TimeOutType()/Details().

func Register

func Register(activityFunc interface{})

Register - calls RegisterWithOptions with default registration options.

func RegisterWithOptions

func RegisterWithOptions(activityFunc interface{}, opts RegisterOptions)

RegisterWithOptions registers the activity function with options The user can use options to provide an external name for the activity or leave it empty if no external name is required. This can be used as

client.Register(barActivity, RegisterOptions{})
client.Register(barActivity, RegisterOptions{Name: "barExternal"})

An activity takes a context and input and returns a (result, error) or just error. Examples:

func sampleActivity(ctx context.Context, input []byte) (result []byte, err error)
func sampleActivity(ctx context.Context, arg1 int, arg2 string) (result *customerStruct, err error)
func sampleActivity(ctx context.Context) (err error)
func sampleActivity() (result string, err error)
func sampleActivity(arg1 bool) (result int, err error)
func sampleActivity(arg1 bool) (err error)

Serialization of all primitive types, structures is supported ... except channels, functions, variadic, unsafe pointer. If function implementation returns activity.ErrResultPending then activity is not completed from the calling workflow point of view. See documentation of activity.ErrResultPending for more info. This method calls panic if activityFunc doesn't comply with the expected format.

Types

type Info

type Info = internal.ActivityInfo

Info contains information about a currently executing activity.

func GetInfo

func GetInfo(ctx context.Context) Info

GetInfo returns information about currently executing activity.

type RegisterOptions

type RegisterOptions = internal.RegisterActivityOptions

RegisterOptions consists of options for registering an activity

type Type

type Type = internal.ActivityType

Type identifies an activity type.

Jump to

Keyboard shortcuts

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