44
45
// AddChild adds a new operation child machine to the given node and transitions it to the SCHEDULED state.
46
>
func AddChild(node *hsm.Node, id string, event *historypb.HistoryEvent, eventToken []byte) (*hsm.Node, error) {
statemachine.go
47
>
attrs := event.GetNexusOperationScheduledEventAttributes()
48
>
49
>
node, err := node.AddChild(hsm.Key{Type: OperationMachineType, ID: id}, Operation{
50
>
&persistencespb.NexusOperationInfo{
51
>
EndpointId: attrs.EndpointId,
52
>
Endpoint: attrs.Endpoint,
53
>
Service: attrs.Service,
54
>
Operation: attrs.Operation,
55
>
ScheduledTime: event.EventTime,
56
>
ScheduleToCloseTimeout: attrs.ScheduleToCloseTimeout,
57
>
ScheduleToStartTimeout: attrs.ScheduleToStartTimeout,
58
>
StartToCloseTimeout: attrs.StartToCloseTimeout,
59
>
RequestId: attrs.RequestId,
60
>
State: enumsspb.NEXUS_OPERATION_STATE_UNSPECIFIED,
61
>
ScheduledEventToken: eventToken,
62
>
},
63
>
})
64
>
65
>
if err != nil {
66
return nil, err
67
}
68
69
>
return node, hsm.MachineTransition(node, func(op Operation) (hsm.TransitionOutput, error) {
statemachine.go
70
>
output, err := TransitionScheduled.Apply(op, EventScheduled{Node: node})
71
>
if err != nil {
72
return output, err
73
}
75
>
if err != nil {
76
return output, err
77
}
79
>
return output, err
80
})
81
}