How to spawn an Activity Execution in Go
To spawn an Activity Execution, use the ExecuteActivity()
API call inside your Workflow Definition.
The API is available from the go.temporal.io/sdk/workflow
package.
The ExecuteActivity()
API call requires an instance of workflow.Context
, the Activity function name, and any variables to be passed to the Activity Execution.
import (
// ...
"go.temporal.io/sdk/workflow"
)
func YourWorkflowDefinition(ctx workflow.Context, param YourWorkflowParam) (YourWorkflowResponse, error) {
// ...
yourActivityParam := YourActivityParam{
// ...
}
var activities *YourActivityStruct
future := workflow.ExecuteActivity(ctx, activities.YourActivityDefinition, yourActivityParam)
// ...
}
func (a *YourActivityStruct) YourActivityDefinition(ctx context.Context, param YourActivityParam) error {
// ...
}
The Activity function name can be provided as a variable object (no quotations) or as a string.
// ...
future := workflow.ExecuteActivity(ctx, "YourActivityDefinition", yourActivityParam)
// ...
The benefit of passing the actual function object is that the framework can validate the parameters against the Activity Definition.
The ExecuteActivity
call returns a Future, which can be used to get the result of the Activity Execution.