tks for your patience
maybe there is some misunderstanding , let me show u the code
with the codes below. when i send signal “SkipErrActivityForOneTime=true” , the whole workflow was canceled, but my expect is cancel/skip the activity only. what is wrong?
the workflow
func GreetingWorkflow(ctx workflow.Context, name string) (string, error) {
options := workflow.ActivityOptions{
...
}
ctx = workflow.WithActivityOptions(ctx, options)
var result string
// failed immediately
err := workflow.ExecuteActivity(ctx, activities.ComposeGreeting, activities.GreetingParam{"jack"}).Get(ctx, &result)
if err != nil {
return "", err
}
// other activities ...
return "", nil
}
the activity
// failed immediately
func ComposeGreeting(param GreetingParam) (string, error) {
return "", errors.New("bad error greeting")
}
the interceptor
save param pointer to ctx
func (w *workflowInboundInterceptor) ExecuteWorkflow(
ctx workflow.Context,
in *interceptor.ExecuteWorkflowInput,
) (interface{}, error) {
// save the pointer to ctx
cancelFuncP := cancelFuncStruct{cancelFunc: nil, cancelActivity: nil}
ctx = workflow.WithValue(ctx, "pauseCancelFunc", &cancelFuncP)
flowControl := workflows.FlowControl{}
ctx = workflow.WithValue(ctx, "flowControl", &flowControl)
// fetch signal aync
workflow.Go(ctx, flowSignalHandler)
return w.Next.ExecuteWorkflow(ctx, in)
}
expose the cancelHandler to ctx
func (w *workflowOutboundInterceptor) ExecuteActivity(ctx workflow.Context, activityType string, args ...interface{}) workflow.Future {
childCtx, cancelHandler := workflow.WithCancel(ctx)
cancelFuncP := ctx.Value("pauseCancelFunc").(*cancelFuncStruct)
cancelFuncP.cancelActivity = cancelHandler
wFuture := w.Next.ExecuteActivity(childCtx, activityType, args...)
return wFuture
}
flowSignalHandler to handle singal
func flowSignalHandler(ctx workflow.Context) {
flowControl := ctx.Value("flowControl").(*workflows.FlowControl)
signalChan := workflow.GetSignalChannel(ctx, "flowControl")
// keep handler signal in the loop
for {
signalChan.Receive(ctx, &flowControl)
if flowControl.SkipErrActivityForOneTime == true {
// try to cancel activity execution
cancelFuncP := ctx.Value("pauseCancelFunc").(*cancelFuncStruct)
cancelFuncP.cancelActivity()
}
}
}