statemachine.go ×14

Frontier kind: Code frontier

unlabeled · c_47c634713d09

108 tests · 2779 LOC · 131 files · introduces 0 tests · 59 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges59 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
449 ranges2779 lines · 131 files · Browse complete extent
All tests (intent)
108 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 59 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/components/nexusoperations/statemachine.go 51 introduced LOC · 14 ranges

Open complete file

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 }
74 > creationTasks, err := op.creationTasks() statemachine.go
75 > if err != nil {
76 return output, err
77 }
78 > output.Tasks = append(output.Tasks, creationTasks...) statemachine.go
79 > return output, err
80 })
81 }
85 }
86
87 > func (o Operation) SetState(state enumsspb.NexusOperationState) { statemachine.go
88 > o.NexusOperationInfo.State = state
89 > }
90
91 func (o Operation) recordAttempt(ts time.Time) {
127
128 // transitionTasks returns tasks that are emitted as transition outputs.
129 > func (o Operation) transitionTasks() ([]hsm.Task, error) { statemachine.go
130 > switch o.State() { // nolint:exhaustive
131 case enumsspb.NEXUS_OPERATION_STATE_BACKING_OFF:
132 return []hsm.Task{BackoffTask{deadline: o.NextAttemptScheduleTime.AsTime()}}, nil
133 > case enumsspb.NEXUS_OPERATION_STATE_SCHEDULED: statemachine.go
134 > return []hsm.Task{InvocationTask{EndpointName: o.Endpoint, Attempt: o.Attempt}}, nil
135 default:
136 return nil, nil
139
140 // creationTasks returns tasks that are emitted when the machine is created.
141 > func (o Operation) creationTasks() ([]hsm.Task, error) { statemachine.go
142 > var tasks []hsm.Task
143 >
144 > if o.ScheduleToCloseTimeout.AsDuration() != 0 {
145 tasks = append(tasks, ScheduleToCloseTimeoutTask{
146 deadline: o.ScheduledTime.AsTime().Add(o.ScheduleToCloseTimeout.AsDuration()),
148 }
149
150 > if o.ScheduleToStartTimeout.AsDuration() != 0 { statemachine.go
151 tasks = append(tasks, ScheduleToStartTimeoutTask{
152 deadline: o.ScheduledTime.AsTime().Add(o.ScheduleToStartTimeout.AsDuration()),
182 }
183
184 > func (o Operation) output() (hsm.TransitionOutput, error) { statemachine.go
185 > tasks, err := o.transitionTasks()
186 > if err != nil {
187 return hsm.TransitionOutput{}, err
188 }
189 > return hsm.TransitionOutput{Tasks: tasks}, nil statemachine.go
190 }
191
201 }
202
203 > func (operationMachineDefinition) Serialize(state any) ([]byte, error) { statemachine.go
204 > if state, ok := state.(Operation); ok {
205 > return proto.Marshal(state.NexusOperationInfo)
206 > }
207 return nil, fmt.Errorf("invalid operation provided: %v", state)
208 }
246 []enumsspb.NexusOperationState{enumsspb.NEXUS_OPERATION_STATE_UNSPECIFIED},
247 enumsspb.NEXUS_OPERATION_STATE_SCHEDULED,
248 > func(op Operation, event EventScheduled) (hsm.TransitionOutput, error) { statemachine.go
249 > return op.output()
250 > },
251 )
252
go.temporal.io/server/api/persistence/v1/executions.pb.go 8 introduced LOC · 1 range

Open complete file

4078 func (*NexusOperationInfo) ProtoMessage() {}
4079
4080 > func (x *NexusOperationInfo) ProtoReflect() protoreflect.Message { executions.pb.go
4081 > mi := &file_temporal_server_api_persistence_v1_executions_proto_msgTypes[26]
4082 > if x != nil {
4083 > ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
4084 > if ms.LoadMessageInfo() == nil {
4085 > ms.StoreMessageInfo(mi)
4086 > }
4087 > return ms
4088 }
4089 return mi.MessageOf(x)