go.temporal.io/server/components/nexusoperations/events.go
359 LOC · 156 covered · 203 uncovered · 57 ranges · 367 concepts · 27 introducers · 165 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
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 related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package nexusoperations
import (
"fmt"
"reflect"
"strconv"
enumspb "go.temporal.io/api/enums/v1"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/server/service/history/hsm"
)
type ScheduledEventDefinition struct{}
func (d ScheduledEventDefinition) IsWorkflowTaskTrigger() bool {
return false
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED
}
func (d ScheduledEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
events.go ×2
token, err := root.GenerateEventLoadToken(event)
if err != nil {
return err
}
return err
}
func (d ScheduledEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, _ map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×6
// We never cherry pick command events, and instead allow user logic to reschedule those commands.
return hsm.ErrNotCherryPickable
}
type CancelRequestedEventDefinition struct{}
func (d CancelRequestedEventDefinition) IsWorkflowTaskTrigger() bool {
return false
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED
}
func (d CancelRequestedEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
commands.go ×4
_, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
})
}
func (d CancelRequestedEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, _ map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×6
// We never cherry pick command events, and instead allow user logic to reschedule those commands.
return hsm.ErrNotCherryPickable
}
type CancelRequestCompletedEventDefinition struct{}
func (d CancelRequestCompletedEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUEST_COMPLETED
}
func (d CancelRequestCompletedEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
_, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
child, err := o.CancelationNode(node)
if err != nil {
return hsm.TransitionOutput{}, err
}
if child != nil {
return hsm.TransitionOutput{}, hsm.MachineTransition(child, func(c Cancelation) (hsm.TransitionOutput, error) {
return TransitionCancelationSucceeded.Apply(c, EventCancelationSucceeded{
Time: event.EventTime.AsTime(),
Node: child,
})
})
}
return hsm.TransitionOutput{}, nil
})
return err
}
func (d CancelRequestCompletedEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, _ map[enumspb.ResetReapplyExcludeType]struct{}) error {
// We never cherry pick command events, and instead allow user logic to reschedule those commands.
return hsm.ErrNotCherryPickable
}
type CancelRequestFailedEventDefinition struct{}
func (d CancelRequestFailedEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUEST_FAILED
}
func (d CancelRequestFailedEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
_, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
child, err := o.CancelationNode(node)
if err != nil {
return hsm.TransitionOutput{}, err
}
if child != nil {
return hsm.TransitionOutput{}, hsm.MachineTransition(child, func(c Cancelation) (hsm.TransitionOutput, error) {
return TransitionCancelationFailed.Apply(c, EventCancelationFailed{
Time: event.EventTime.AsTime(),
Failure: event.GetNexusOperationCancelRequestFailedEventAttributes().GetFailure(),
Node: child,
})
})
}
return hsm.TransitionOutput{}, nil
})
return err
}
func (d CancelRequestFailedEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, _ map[enumspb.ResetReapplyExcludeType]struct{}) error {
// We never cherry pick command events, and instead allow user logic to reschedule those commands.
return hsm.ErrNotCherryPickable
}
type StartedEventDefinition struct{}
func (d StartedEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_STARTED
}
func (d StartedEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
events.go ×2
_, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
Time: event.EventTime.AsTime(),
Node: node,
Attributes: event.GetNexusOperationStartedEventAttributes(),
})
})
}
func (d StartedEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, excludeTypes map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×1
if _, ok := excludeTypes[enumspb.RESET_REAPPLY_EXCLUDE_TYPE_NEXUS]; ok {
}
}
type CompletedEventDefinition struct{}
func (d CompletedEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
func (d CompletedEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
events.go ×2
node, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
return TransitionSucceeded.Apply(o, EventSucceeded{
Time: event.EventTime.AsTime(),
Node: node,
})
})
if err != nil {
return err
}
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_COMPLETED
}
func (d CompletedEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, excludeTypes map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×6
if _, ok := excludeTypes[enumspb.RESET_REAPPLY_EXCLUDE_TYPE_NEXUS]; ok {
return hsm.ErrNotCherryPickable
}
return d.Apply(root, event)
}
type FailedEventDefinition struct{}
func (d FailedEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_FAILED
}
func (d FailedEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
events.go ×2
node, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
return TransitionFailed.Apply(o, EventFailed{
Time: event.EventTime.AsTime(),
Attributes: event.GetNexusOperationFailedEventAttributes(),
Node: node,
})
})
if err != nil {
return err
}
}
func (d FailedEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, excludeTypes map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×6
if _, ok := excludeTypes[enumspb.RESET_REAPPLY_EXCLUDE_TYPE_NEXUS]; ok {
return hsm.ErrNotCherryPickable
}
return d.Apply(root, event)
}
type CanceledEventDefinition struct{}
func (d CanceledEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_CANCELED
}
func (d CanceledEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
events.go ×2
node, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
return TransitionCanceled.Apply(o, EventCanceled{
Time: event.EventTime.AsTime(),
Node: node,
})
})
if err != nil {
return err
}
}
func (d CanceledEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, excludeTypes map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×6
if _, ok := excludeTypes[enumspb.RESET_REAPPLY_EXCLUDE_TYPE_NEXUS]; ok {
return hsm.ErrNotCherryPickable
}
return d.Apply(root, event)
}
type TimedOutEventDefinition struct{}
func (d TimedOutEventDefinition) IsWorkflowTaskTrigger() bool {
return true
}
return enumspb.EVENT_TYPE_NEXUS_OPERATION_TIMED_OUT
}
func (d TimedOutEventDefinition) Apply(root *hsm.Node, event *historypb.HistoryEvent) error {
events.go ×2
node, err := transitionOperation(root, event, func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error) {
return TransitionTimedOut.Apply(o, EventTimedOut{
Node: node,
})
})
if err != nil {
return err
}
}
func (d TimedOutEventDefinition) CherryPick(root *hsm.Node, event *historypb.HistoryEvent, excludeTypes map[enumspb.ResetReapplyExcludeType]struct{}) error {
events.go ×6
if _, ok := excludeTypes[enumspb.RESET_REAPPLY_EXCLUDE_TYPE_NEXUS]; ok {
return hsm.ErrNotCherryPickable
}
return d.Apply(root, event)
}
if err := reg.RegisterEventDefinition(ScheduledEventDefinition{}); err != nil {
return err
}
if err := reg.RegisterEventDefinition(CancelRequestedEventDefinition{}); err != nil {
events.go ×13
return err
}
if err := reg.RegisterEventDefinition(CancelRequestCompletedEventDefinition{}); err != nil {
events.go ×13
return err
}
if err := reg.RegisterEventDefinition(CancelRequestFailedEventDefinition{}); err != nil {
events.go ×13
return err
}
return err
}
return err
}
return err
}
return err
}
}
func transitionOperation(
root *hsm.Node,
event *historypb.HistoryEvent,
fn func(node *hsm.Node, o Operation) (hsm.TransitionOutput, error),
node, err := findOperationNode(root, event)
if err != nil {
}
if err := hsm.MachineTransition(node, func(o Operation) (hsm.TransitionOutput, error) {
events.go ×3
return fn(node, o)
}); err != nil {
}
}
func findOperationNode(root *hsm.Node, event *historypb.HistoryEvent) (*hsm.Node, error) {
events.go ×4
attrs := reflect.ValueOf(event.Attributes).Elem()
// Attributes is always a struct with a single field (e.g: HistoryEvent_NexusOperationScheduledEventAttributes)
if attrs.Kind() != reflect.Struct || attrs.NumField() != 1 {
panic("invalid event, expected Attributes field with a single field struct")
}
eventIDGetter, ok := f.(interface{ GetScheduledEventId() int64 })
if !ok {
panic("Event does not have a ScheduledEventId field")
}
nodeID := strconv.FormatInt(eventIDGetter.GetScheduledEventId(), 10)
node, err := coll.Node(nodeID)
if err != nil {
}
if ok && requestIDGetter.GetRequestId() != "" {
if err != nil {
return nil, err
}
return nil, fmt.Errorf("%w: event has different request ID (%q) than the machine (%q)",
events.go ×1
hsm.ErrNotCherryPickable, requestIDGetter.GetRequestId(), op.RequestId)
}
}
}