Skip to content

Commit ffd9933

Browse files
committed
Addressed PR comments
Signed-off-by: Albert Callarisa <albert@diagrid.io>
1 parent 915a8f9 commit ffd9933

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

api/helpers/task.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package helpers
22

33
import (
4-
"fmt"
54
"reflect"
65
"runtime"
6+
"strconv"
77
"strings"
88
)
99

1010
// GenerateChildWorkflowInstanceID generates a deterministic instance ID for a
1111
// child workflow based on the parent instance ID and the action's sequence number.
1212
func GenerateChildWorkflowInstanceID(parentInstanceID string, actionID int32) string {
13-
return fmt.Sprintf("%s:%04x", parentInstanceID, actionID)
13+
// Adding 0x10000 guarantees at least 5 hex digits (e.g. 0 → "10000"),
14+
// so taking the last 4 gives a zero-padded result (e.g. "0000").
15+
hex := strconv.FormatInt(0x10000+int64(actionID), 16)
16+
hex = hex[len(hex)-4:]
17+
return parentInstanceID + ":" + hex
1418
}
1519

1620
func GetTaskFunctionName(f any) string {

backend/runtimestate/applier.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,17 @@ func (a *Applier) Actions(s *protos.WorkflowRuntimeState, customStatus *wrappers
151151
FireAt: timerAction.FireAt,
152152
Name: timerAction.Name,
153153
}
154-
if externalEvent := timerAction.GetExternalEvent(); externalEvent != nil {
155-
timerCreated.Origin = &protos.TimerCreatedEvent_ExternalEvent{
156-
ExternalEvent: externalEvent,
157-
}
158-
} else if ct := timerAction.GetCreateTimer(); ct != nil {
159-
timerCreated.Origin = &protos.TimerCreatedEvent_CreateTimer{
160-
CreateTimer: ct,
161-
}
162-
} else if ar := timerAction.GetActivityRetry(); ar != nil {
163-
timerCreated.Origin = &protos.TimerCreatedEvent_ActivityRetry{
164-
ActivityRetry: ar,
165-
}
166-
} else if cwr := timerAction.GetChildWorkflowRetry(); cwr != nil {
167-
timerCreated.Origin = &protos.TimerCreatedEvent_ChildWorkflowRetry{
168-
ChildWorkflowRetry: cwr,
169-
}
154+
switch o := timerAction.GetOrigin().(type) {
155+
case *protos.CreateTimerAction_CreateTimer:
156+
timerCreated.Origin = &protos.TimerCreatedEvent_CreateTimer{CreateTimer: o.CreateTimer}
157+
case *protos.CreateTimerAction_ExternalEvent:
158+
timerCreated.Origin = &protos.TimerCreatedEvent_ExternalEvent{ExternalEvent: o.ExternalEvent}
159+
case *protos.CreateTimerAction_ActivityRetry:
160+
timerCreated.Origin = &protos.TimerCreatedEvent_ActivityRetry{ActivityRetry: o.ActivityRetry}
161+
case *protos.CreateTimerAction_ChildWorkflowRetry:
162+
timerCreated.Origin = &protos.TimerCreatedEvent_ChildWorkflowRetry{ChildWorkflowRetry: o.ChildWorkflowRetry}
163+
default:
164+
return false, fmt.Errorf("unknown timer origin type: %T", timerAction.GetOrigin())
170165
}
171166
_ = AddEvent(s, &protos.HistoryEvent{
172167
EventId: action.Id,

0 commit comments

Comments
 (0)