|
| 1 | +// The MIT License |
| 2 | +// |
| 3 | +// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Uber Technologies, Inc. |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files (the "Software"), to deal |
| 9 | +// in the Software without restriction, including without limitation the rights |
| 10 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +// copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +// THE SOFTWARE. |
| 24 | + |
| 25 | +package removesignalmutablestate |
| 26 | + |
| 27 | +import ( |
| 28 | + "context" |
| 29 | + |
| 30 | + "go.temporal.io/server/api/historyservice/v1" |
| 31 | + "go.temporal.io/server/common/definition" |
| 32 | + "go.temporal.io/server/common/namespace" |
| 33 | + "go.temporal.io/server/service/history/api" |
| 34 | + "go.temporal.io/server/service/history/consts" |
| 35 | + "go.temporal.io/server/service/history/shard" |
| 36 | +) |
| 37 | + |
| 38 | +func Invoke( |
| 39 | + ctx context.Context, |
| 40 | + req *historyservice.RemoveSignalMutableStateRequest, |
| 41 | + shard shard.Context, |
| 42 | + workflowConsistencyChecker api.WorkflowConsistencyChecker, |
| 43 | +) (resp *historyservice.RemoveSignalMutableStateResponse, retError error) { |
| 44 | + _, err := api.GetActiveNamespace(shard, namespace.ID(req.GetNamespaceId())) |
| 45 | + if err != nil { |
| 46 | + return nil, err |
| 47 | + } |
| 48 | + |
| 49 | + err = api.GetAndUpdateWorkflowWithNew( |
| 50 | + ctx, |
| 51 | + nil, |
| 52 | + api.BypassMutableStateConsistencyPredicate, |
| 53 | + definition.NewWorkflowKey( |
| 54 | + req.NamespaceId, |
| 55 | + req.WorkflowExecution.WorkflowId, |
| 56 | + req.WorkflowExecution.RunId, |
| 57 | + ), |
| 58 | + func(workflowContext api.WorkflowContext) (*api.UpdateWorkflowAction, error) { |
| 59 | + mutableState := workflowContext.GetMutableState() |
| 60 | + if !mutableState.IsWorkflowExecutionRunning() { |
| 61 | + return nil, consts.ErrWorkflowCompleted |
| 62 | + } |
| 63 | + |
| 64 | + mutableState.DeleteSignalRequested(req.GetRequestId()) |
| 65 | + return &api.UpdateWorkflowAction{ |
| 66 | + Noop: false, |
| 67 | + CreateWorkflowTask: false, |
| 68 | + }, nil |
| 69 | + }, |
| 70 | + nil, |
| 71 | + shard, |
| 72 | + workflowConsistencyChecker, |
| 73 | + ) |
| 74 | + if err != nil { |
| 75 | + return nil, err |
| 76 | + } |
| 77 | + return &historyservice.RemoveSignalMutableStateResponse{}, nil |
| 78 | +} |
0 commit comments