86
87
// ProcessorActivity is activity for processing batch operation
88
>
func ProcessorActivity(ctx context.Context, request Request) error {
workflow.go
89
>
processor := ctx.Value(processorContextKey).(*Processor)
90
>
client := processor.clientBean.GetHistoryClient()
91
>
// this is for backward compatibility
92
>
// ideally we should always have childWorkflowOnly = true
93
>
// however if ParentExecution is not specified, setting it to false
94
>
// will cause terminate or cancel request to return mismatch error
95
>
childWorkflowOnly := request.ParentExecution.GetWorkflowId() != "" &&
96
>
request.ParentExecution.GetRunId() != ""
97
>
98
>
remoteExecutions := make(map[string][]RequestDetail)
99
>
for _, execution := range request.Executions {
100
>
requestCtx := headers.SetCallerName(ctx, execution.Namespace)
101
>
102
>
var err error
103
>
switch execution.Policy {
104
case enumspb.PARENT_CLOSE_POLICY_ABANDON:
105
// no-op
106
continue
107
>
case enumspb.PARENT_CLOSE_POLICY_TERMINATE:
workflow.go
108
>
_, err = client.TerminateWorkflowExecution(requestCtx, &historyservice.TerminateWorkflowExecutionRequest{
109
>
NamespaceId: execution.NamespaceID,
110
>
TerminateRequest: &workflowservice.TerminateWorkflowExecutionRequest{
111
>
Namespace: execution.Namespace,
112
>
WorkflowExecution: &commonpb.WorkflowExecution{
113
>
WorkflowId: execution.WorkflowID,
114
>
},
115
>
Reason: "by parent close policy",
116
>
Identity: processorWFTypeName,
117
>
FirstExecutionRunId: execution.RunID,
118
>
},
119
>
ExternalWorkflowExecution: request.ParentExecution,
120
>
ChildWorkflowOnly: childWorkflowOnly,
121
>
})
122
>
case enumspb.PARENT_CLOSE_POLICY_REQUEST_CANCEL:
123
>
_, err = client.RequestCancelWorkflowExecution(requestCtx, &historyservice.RequestCancelWorkflowExecutionRequest{
124
>
NamespaceId: execution.NamespaceID,
125
>
CancelRequest: &workflowservice.RequestCancelWorkflowExecutionRequest{
126
>
Namespace: execution.Namespace,
127
>
WorkflowExecution: &commonpb.WorkflowExecution{
128
>
WorkflowId: execution.WorkflowID,
129
>
},
130
>
Identity: processorWFTypeName,
131
>
FirstExecutionRunId: execution.RunID,
132
>
},
133
>
ExternalWorkflowExecution: request.ParentExecution,
134
>
ChildWorkflowOnly: childWorkflowOnly,
135
>
})
136
}
137
139
case nil:
140
metrics.ParentClosePolicyProcessorSuccess.With(processor.metricsHandler).Record(1)