6565 state decisionState
6666 history []string
6767 data interface {}
68+ helper * decisionsHelper
6869 }
6970
7071 activityDecisionStateMachine struct {
@@ -207,67 +208,68 @@ func makeDecisionID(decisionType decisionType, id string) decisionID {
207208 return decisionID {decisionType : decisionType , id : id }
208209}
209210
210- func newDecisionStateMachineBase (decisionType decisionType , id string ) * decisionStateMachineBase {
211+ func ( h * decisionsHelper ) newDecisionStateMachineBase (decisionType decisionType , id string ) * decisionStateMachineBase {
211212 return & decisionStateMachineBase {
212213 id : makeDecisionID (decisionType , id ),
213214 state : decisionStateCreated ,
214215 history : []string {decisionStateCreated .String ()},
216+ helper : h ,
215217 }
216218}
217219
218- func newActivityDecisionStateMachine (attributes * s.ScheduleActivityTaskDecisionAttributes ) * activityDecisionStateMachine {
219- base := newDecisionStateMachineBase (decisionTypeActivity , attributes .GetActivityId ())
220+ func ( h * decisionsHelper ) newActivityDecisionStateMachine (attributes * s.ScheduleActivityTaskDecisionAttributes ) * activityDecisionStateMachine {
221+ base := h . newDecisionStateMachineBase (decisionTypeActivity , attributes .GetActivityId ())
220222 return & activityDecisionStateMachine {
221223 decisionStateMachineBase : base ,
222224 attributes : attributes ,
223225 }
224226}
225227
226- func newTimerDecisionStateMachine (attributes * s.StartTimerDecisionAttributes ) * timerDecisionStateMachine {
227- base := newDecisionStateMachineBase (decisionTypeTimer , attributes .GetTimerId ())
228+ func ( h * decisionsHelper ) newTimerDecisionStateMachine (attributes * s.StartTimerDecisionAttributes ) * timerDecisionStateMachine {
229+ base := h . newDecisionStateMachineBase (decisionTypeTimer , attributes .GetTimerId ())
228230 return & timerDecisionStateMachine {
229231 decisionStateMachineBase : base ,
230232 attributes : attributes ,
231233 }
232234}
233235
234- func newChildWorkflowDecisionStateMachine (attributes * s.StartChildWorkflowExecutionDecisionAttributes ) * childWorkflowDecisionStateMachine {
235- base := newDecisionStateMachineBase (decisionTypeChildWorkflow , attributes .GetWorkflowId ())
236+ func ( h * decisionsHelper ) newChildWorkflowDecisionStateMachine (attributes * s.StartChildWorkflowExecutionDecisionAttributes ) * childWorkflowDecisionStateMachine {
237+ base := h . newDecisionStateMachineBase (decisionTypeChildWorkflow , attributes .GetWorkflowId ())
236238 return & childWorkflowDecisionStateMachine {
237239 decisionStateMachineBase : base ,
238240 attributes : attributes ,
239241 }
240242}
241243
242- func newNaiveDecisionStateMachine (decisionType decisionType , id string , decision * s.Decision ) * naiveDecisionStateMachine {
243- base := newDecisionStateMachineBase (decisionType , id )
244+ func ( h * decisionsHelper ) newNaiveDecisionStateMachine (decisionType decisionType , id string , decision * s.Decision ) * naiveDecisionStateMachine {
245+ base := h . newDecisionStateMachineBase (decisionType , id )
244246 return & naiveDecisionStateMachine {
245247 decisionStateMachineBase : base ,
246248 decision : decision ,
247249 }
248250}
249251
250- func newMarkerDecisionStateMachine (id string , attributes * s.RecordMarkerDecisionAttributes ) * markerDecisionStateMachine {
252+ func ( h * decisionsHelper ) newMarkerDecisionStateMachine (id string , attributes * s.RecordMarkerDecisionAttributes ) * markerDecisionStateMachine {
251253 d := createNewDecision (s .DecisionTypeRecordMarker )
252254 d .RecordMarkerDecisionAttributes = attributes
253255 return & markerDecisionStateMachine {
254- naiveDecisionStateMachine : newNaiveDecisionStateMachine (decisionTypeMarker , id , d ),
256+ naiveDecisionStateMachine : h . newNaiveDecisionStateMachine (decisionTypeMarker , id , d ),
255257 }
256258}
257259
258- func newCancelExternalWorkflowStateMachine (attributes * s.RequestCancelExternalWorkflowExecutionDecisionAttributes , cancellationID string ) * cancelExternalWorkflowDecisionStateMachine {
260+ func ( h * decisionsHelper ) newCancelExternalWorkflowStateMachine (attributes * s.RequestCancelExternalWorkflowExecutionDecisionAttributes , cancellationID string ) * cancelExternalWorkflowDecisionStateMachine {
259261 d := createNewDecision (s .DecisionTypeRequestCancelExternalWorkflowExecution )
260262 d .RequestCancelExternalWorkflowExecutionDecisionAttributes = attributes
261263 return & cancelExternalWorkflowDecisionStateMachine {
262- naiveDecisionStateMachine : newNaiveDecisionStateMachine (decisionTypeCancellation , cancellationID , d ),
264+ naiveDecisionStateMachine : h . newNaiveDecisionStateMachine (decisionTypeCancellation , cancellationID , d ),
263265 }
264266}
265267
266- func newSignalExternalWorkflowStateMachine (attributes * s.SignalExternalWorkflowExecutionDecisionAttributes , signalID string ) * signalExternalWorkflowDecisionStateMachine {
268+ func ( h * decisionsHelper ) newSignalExternalWorkflowStateMachine (attributes * s.SignalExternalWorkflowExecutionDecisionAttributes , signalID string ) * signalExternalWorkflowDecisionStateMachine {
267269 d := createNewDecision (s .DecisionTypeSignalExternalWorkflowExecution )
268270 d .SignalExternalWorkflowExecutionDecisionAttributes = attributes
269271 return & signalExternalWorkflowDecisionStateMachine {
270- naiveDecisionStateMachine : newNaiveDecisionStateMachine (decisionTypeSignal , signalID , d ),
272+ naiveDecisionStateMachine : h . newNaiveDecisionStateMachine (decisionTypeSignal , signalID , d ),
271273 }
272274}
273275
@@ -295,6 +297,13 @@ func (d *decisionStateMachineBase) moveState(newState decisionState, event strin
295297 d .history = append (d .history , event )
296298 d .state = newState
297299 d .history = append (d .history , newState .String ())
300+
301+ if newState == decisionStateCompleted {
302+ if elem , ok := d .helper .decisions [d .getID ()]; ok {
303+ d .helper .orderedDecisions .Remove (elem )
304+ delete (d .helper .decisions , d .getID ())
305+ }
306+ }
298307}
299308
300309func (d * decisionStateMachineBase ) failStateTransition (event string ) {
@@ -660,12 +669,16 @@ func (h *decisionsHelper) getDecision(id decisionID) decisionStateMachine {
660669}
661670
662671func (h * decisionsHelper ) addDecision (decision decisionStateMachine ) {
672+ if _ , ok := h .decisions [decision .getID ()]; ok {
673+ panicMsg := fmt .Sprintf ("adding duplicate decision %v" , decision )
674+ panic (panicMsg )
675+ }
663676 element := h .orderedDecisions .PushBack (decision )
664677 h .decisions [decision .getID ()] = element
665678}
666679
667680func (h * decisionsHelper ) scheduleActivityTask (attributes * s.ScheduleActivityTaskDecisionAttributes ) decisionStateMachine {
668- decision := newActivityDecisionStateMachine (attributes )
681+ decision := h . newActivityDecisionStateMachine (attributes )
669682 h .addDecision (decision )
670683 return decision
671684}
@@ -739,7 +752,7 @@ func (h *decisionsHelper) recordVersionMarker(changeID string, version Version,
739752 Details : details , // Keep
740753 }
741754
742- decision := newMarkerDecisionStateMachine (markerID , recordMarker )
755+ decision := h . newMarkerDecisionStateMachine (markerID , recordMarker )
743756 h .addDecision (decision )
744757 return decision
745758}
@@ -750,7 +763,7 @@ func (h *decisionsHelper) recordSideEffectMarker(sideEffectID int32, data []byte
750763 MarkerName : common .StringPtr (sideEffectMarkerName ),
751764 Details : data ,
752765 }
753- decision := newMarkerDecisionStateMachine (markerID , attributes )
766+ decision := h . newMarkerDecisionStateMachine (markerID , attributes )
754767 h .addDecision (decision )
755768 return decision
756769}
@@ -761,7 +774,7 @@ func (h *decisionsHelper) recordLocalActivityMarker(activityID string, result []
761774 MarkerName : common .StringPtr (localActivityMarkerName ),
762775 Details : result ,
763776 }
764- decision := newMarkerDecisionStateMachine (markerID , attributes )
777+ decision := h . newMarkerDecisionStateMachine (markerID , attributes )
765778 h .addDecision (decision )
766779 return decision
767780}
@@ -772,13 +785,13 @@ func (h *decisionsHelper) recordMutableSideEffectMarker(mutableSideEffectID stri
772785 MarkerName : common .StringPtr (mutableSideEffectMarkerName ),
773786 Details : data ,
774787 }
775- decision := newMarkerDecisionStateMachine (markerID , attributes )
788+ decision := h . newMarkerDecisionStateMachine (markerID , attributes )
776789 h .addDecision (decision )
777790 return decision
778791}
779792
780793func (h * decisionsHelper ) startChildWorkflowExecution (attributes * s.StartChildWorkflowExecutionDecisionAttributes ) decisionStateMachine {
781- decision := newChildWorkflowDecisionStateMachine (attributes )
794+ decision := h . newChildWorkflowDecisionStateMachine (attributes )
782795 h .addDecision (decision )
783796 return decision
784797}
@@ -833,7 +846,7 @@ func (h *decisionsHelper) requestCancelExternalWorkflowExecution(domain, workflo
833846 Control : []byte (cancellationID ),
834847 ChildWorkflowOnly : common .BoolPtr (false ),
835848 }
836- decision := newCancelExternalWorkflowStateMachine (attributes , cancellationID )
849+ decision := h . newCancelExternalWorkflowStateMachine (attributes , cancellationID )
837850 h .addDecision (decision )
838851
839852 return decision
@@ -893,7 +906,7 @@ func (h *decisionsHelper) signalExternalWorkflowExecution(domain, workflowID, ru
893906 Control : []byte (signalID ),
894907 ChildWorkflowOnly : common .BoolPtr (childWorkflowOnly ),
895908 }
896- decision := newSignalExternalWorkflowStateMachine (attributes , signalID )
909+ decision := h . newSignalExternalWorkflowStateMachine (attributes , signalID )
897910 h .addDecision (decision )
898911 return decision
899912}
@@ -925,7 +938,7 @@ func (h *decisionsHelper) getSignalID(initiatedEventID int64) string {
925938}
926939
927940func (h * decisionsHelper ) startTimer (attributes * s.StartTimerDecisionAttributes ) decisionStateMachine {
928- decision := newTimerDecisionStateMachine (attributes )
941+ decision := h . newTimerDecisionStateMachine (attributes )
929942 h .addDecision (decision )
930943 return decision
931944}
0 commit comments