go.uber.org/cadence@v1.2.9/internal/compatibility/proto/decision.go (about) 1 // Copyright (c) 2021 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package proto 22 23 import ( 24 "go.uber.org/cadence/.gen/go/shared" 25 26 apiv1 "github.com/uber/cadence-idl/go/proto/api/v1" 27 ) 28 29 func DecisionArray(t []*shared.Decision) []*apiv1.Decision { 30 if t == nil { 31 return nil 32 } 33 v := make([]*apiv1.Decision, len(t)) 34 for i := range t { 35 v[i] = Decision(t[i]) 36 } 37 return v 38 } 39 40 func Decision(d *shared.Decision) *apiv1.Decision { 41 if d == nil { 42 return nil 43 } 44 decision := apiv1.Decision{} 45 switch *d.DecisionType { 46 case shared.DecisionTypeScheduleActivityTask: 47 attr := d.ScheduleActivityTaskDecisionAttributes 48 decision.Attributes = &apiv1.Decision_ScheduleActivityTaskDecisionAttributes{ 49 ScheduleActivityTaskDecisionAttributes: &apiv1.ScheduleActivityTaskDecisionAttributes{ 50 ActivityId: attr.GetActivityId(), 51 ActivityType: ActivityType(attr.ActivityType), 52 Domain: attr.GetDomain(), 53 TaskList: TaskList(attr.TaskList), 54 Input: Payload(attr.Input), 55 ScheduleToCloseTimeout: secondsToDuration(attr.ScheduleToCloseTimeoutSeconds), 56 ScheduleToStartTimeout: secondsToDuration(attr.ScheduleToStartTimeoutSeconds), 57 StartToCloseTimeout: secondsToDuration(attr.StartToCloseTimeoutSeconds), 58 HeartbeatTimeout: secondsToDuration(attr.HeartbeatTimeoutSeconds), 59 RetryPolicy: RetryPolicy(attr.RetryPolicy), 60 Header: Header(attr.Header), 61 RequestLocalDispatch: attr.GetRequestLocalDispatch(), 62 }, 63 } 64 case shared.DecisionTypeRequestCancelActivityTask: 65 attr := d.RequestCancelActivityTaskDecisionAttributes 66 decision.Attributes = &apiv1.Decision_RequestCancelActivityTaskDecisionAttributes{ 67 RequestCancelActivityTaskDecisionAttributes: &apiv1.RequestCancelActivityTaskDecisionAttributes{ 68 ActivityId: attr.GetActivityId(), 69 }, 70 } 71 case shared.DecisionTypeStartTimer: 72 attr := d.StartTimerDecisionAttributes 73 decision.Attributes = &apiv1.Decision_StartTimerDecisionAttributes{ 74 StartTimerDecisionAttributes: &apiv1.StartTimerDecisionAttributes{ 75 TimerId: attr.GetTimerId(), 76 StartToFireTimeout: secondsToDuration(int64To32(attr.StartToFireTimeoutSeconds)), 77 }, 78 } 79 case shared.DecisionTypeCompleteWorkflowExecution: 80 attr := d.CompleteWorkflowExecutionDecisionAttributes 81 decision.Attributes = &apiv1.Decision_CompleteWorkflowExecutionDecisionAttributes{ 82 CompleteWorkflowExecutionDecisionAttributes: &apiv1.CompleteWorkflowExecutionDecisionAttributes{ 83 Result: Payload(attr.Result), 84 }, 85 } 86 case shared.DecisionTypeFailWorkflowExecution: 87 attr := d.FailWorkflowExecutionDecisionAttributes 88 decision.Attributes = &apiv1.Decision_FailWorkflowExecutionDecisionAttributes{ 89 FailWorkflowExecutionDecisionAttributes: &apiv1.FailWorkflowExecutionDecisionAttributes{ 90 Failure: Failure(attr.Reason, attr.Details), 91 }, 92 } 93 case shared.DecisionTypeCancelTimer: 94 attr := d.CancelTimerDecisionAttributes 95 decision.Attributes = &apiv1.Decision_CancelTimerDecisionAttributes{ 96 CancelTimerDecisionAttributes: &apiv1.CancelTimerDecisionAttributes{ 97 TimerId: attr.GetTimerId(), 98 }, 99 } 100 case shared.DecisionTypeCancelWorkflowExecution: 101 attr := d.CancelWorkflowExecutionDecisionAttributes 102 decision.Attributes = &apiv1.Decision_CancelWorkflowExecutionDecisionAttributes{ 103 CancelWorkflowExecutionDecisionAttributes: &apiv1.CancelWorkflowExecutionDecisionAttributes{ 104 Details: Payload(attr.Details), 105 }, 106 } 107 case shared.DecisionTypeRequestCancelExternalWorkflowExecution: 108 attr := d.RequestCancelExternalWorkflowExecutionDecisionAttributes 109 decision.Attributes = &apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes{ 110 RequestCancelExternalWorkflowExecutionDecisionAttributes: &apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes{ 111 Domain: attr.GetDomain(), 112 WorkflowExecution: WorkflowRunPair(attr.GetWorkflowId(), attr.GetRunId()), 113 Control: attr.Control, 114 ChildWorkflowOnly: attr.GetChildWorkflowOnly(), 115 }, 116 } 117 case shared.DecisionTypeRecordMarker: 118 attr := d.RecordMarkerDecisionAttributes 119 decision.Attributes = &apiv1.Decision_RecordMarkerDecisionAttributes{ 120 RecordMarkerDecisionAttributes: &apiv1.RecordMarkerDecisionAttributes{ 121 MarkerName: attr.GetMarkerName(), 122 Details: Payload(attr.Details), 123 Header: Header(attr.Header), 124 }, 125 } 126 case shared.DecisionTypeContinueAsNewWorkflowExecution: 127 attr := d.ContinueAsNewWorkflowExecutionDecisionAttributes 128 decision.Attributes = &apiv1.Decision_ContinueAsNewWorkflowExecutionDecisionAttributes{ 129 ContinueAsNewWorkflowExecutionDecisionAttributes: &apiv1.ContinueAsNewWorkflowExecutionDecisionAttributes{ 130 WorkflowType: WorkflowType(attr.WorkflowType), 131 TaskList: TaskList(attr.TaskList), 132 Input: Payload(attr.Input), 133 ExecutionStartToCloseTimeout: secondsToDuration(attr.ExecutionStartToCloseTimeoutSeconds), 134 TaskStartToCloseTimeout: secondsToDuration(attr.TaskStartToCloseTimeoutSeconds), 135 BackoffStartInterval: secondsToDuration(attr.BackoffStartIntervalInSeconds), 136 RetryPolicy: RetryPolicy(attr.RetryPolicy), 137 Initiator: ContinueAsNewInitiator(attr.Initiator), 138 Failure: Failure(attr.FailureReason, attr.FailureDetails), 139 LastCompletionResult: Payload(attr.LastCompletionResult), 140 CronSchedule: attr.GetCronSchedule(), 141 Header: Header(attr.Header), 142 Memo: Memo(attr.Memo), 143 SearchAttributes: SearchAttributes(attr.SearchAttributes), 144 JitterStart: secondsToDuration(attr.JitterStartSeconds), 145 }, 146 } 147 case shared.DecisionTypeStartChildWorkflowExecution: 148 attr := d.StartChildWorkflowExecutionDecisionAttributes 149 decision.Attributes = &apiv1.Decision_StartChildWorkflowExecutionDecisionAttributes{ 150 StartChildWorkflowExecutionDecisionAttributes: &apiv1.StartChildWorkflowExecutionDecisionAttributes{ 151 Domain: attr.GetDomain(), 152 WorkflowId: attr.GetWorkflowId(), 153 WorkflowType: WorkflowType(attr.WorkflowType), 154 TaskList: TaskList(attr.TaskList), 155 Input: Payload(attr.Input), 156 ExecutionStartToCloseTimeout: secondsToDuration(attr.ExecutionStartToCloseTimeoutSeconds), 157 TaskStartToCloseTimeout: secondsToDuration(attr.TaskStartToCloseTimeoutSeconds), 158 ParentClosePolicy: ParentClosePolicy(attr.ParentClosePolicy), 159 Control: attr.Control, 160 WorkflowIdReusePolicy: WorkflowIdReusePolicy(attr.WorkflowIdReusePolicy), 161 RetryPolicy: RetryPolicy(attr.RetryPolicy), 162 CronSchedule: attr.GetCronSchedule(), 163 Header: Header(attr.Header), 164 Memo: Memo(attr.Memo), 165 SearchAttributes: SearchAttributes(attr.SearchAttributes), 166 }, 167 } 168 case shared.DecisionTypeSignalExternalWorkflowExecution: 169 attr := d.SignalExternalWorkflowExecutionDecisionAttributes 170 decision.Attributes = &apiv1.Decision_SignalExternalWorkflowExecutionDecisionAttributes{ 171 SignalExternalWorkflowExecutionDecisionAttributes: &apiv1.SignalExternalWorkflowExecutionDecisionAttributes{ 172 Domain: attr.GetDomain(), 173 WorkflowExecution: WorkflowExecution(attr.Execution), 174 SignalName: attr.GetSignalName(), 175 Input: Payload(attr.Input), 176 Control: attr.Control, 177 ChildWorkflowOnly: attr.GetChildWorkflowOnly(), 178 }, 179 } 180 case shared.DecisionTypeUpsertWorkflowSearchAttributes: 181 attr := d.UpsertWorkflowSearchAttributesDecisionAttributes 182 decision.Attributes = &apiv1.Decision_UpsertWorkflowSearchAttributesDecisionAttributes{ 183 UpsertWorkflowSearchAttributesDecisionAttributes: &apiv1.UpsertWorkflowSearchAttributesDecisionAttributes{ 184 SearchAttributes: SearchAttributes(attr.SearchAttributes), 185 }, 186 } 187 default: 188 panic("unknown decision type") 189 } 190 return &decision 191 }