I would like to put workflow.Sleep
call in one of my Cadence activities to be able to test it properly (and simulate error result coming from Sleep
function).
Two important things which I noticed before implementing:
context.Context
andworkflow.Context
are separate types.- First parameter of each activity -
context.Context
- is optional and can be omitted
My tries:
1. First try
import "go.uber.org/cadence/workflow"
// Activity:
func (s *MyActivities) WorkflowSleep(_ context.Context, workflowCtx workflow.Context, duration time.Duration) error {
return workflow.Sleep(workflowCtx, duration)
}
// In workflow; ctx has type workflow.Context:
err := workflow.ExecuteActivity(ctx, myActivities.WorkflowSleep, ctx, duration).Get(ctx, nil)
Error:
"error":"unable to decode the activity function input bytes with error: unable to decode argument: 0, *internal.Context, with json error: json: cannot unmarshal object into Go value of type internal.Context for function
2. Second try
import "go.uber.org/cadence/workflow"
// Activity:
func (s *MyActivities) WorkflowSleep(workflowCtx workflow.Context, duration time.Duration) error {
return workflow.Sleep(workflowCtx, duration)
}
// In workflow; ctx has type workflow.Context:
err := workflow.ExecuteActivity(ctx, myActivities.WorkflowSleep, duration).Get(ctx, nil)
Error:
"PanicError":"reflect: Call with too few input arguments"
Question
Is it possible to use workflow.Sleep
inside any activity?