MCPcopy Create free account
hub / github.com/PostHog/duckgres / Validate

Method Validate

controlplane/worker_state.go:96–119  ·  view source on GitHub ↗

Validate checks that the lifecycle and assignment metadata are internally consistent.

()

Source from the content-addressed store, hash-verified

94// Validate checks that the lifecycle and assignment metadata are internally
95// consistent.
96func (s SharedWorkerState) Validate() error {
97 switch lifecycle := s.NormalizedLifecycle(); lifecycle {
98 case WorkerLifecycleIdle:
99 if s.Assignment != nil {
100 return fmt.Errorf("lifecycle %q cannot have an assignment", lifecycle)
101 }
102 return nil
103 case WorkerLifecycleReserved, WorkerLifecycleActivating, WorkerLifecycleHot, WorkerLifecycleHotIdle:
104 if err := validateWorkerAssignment(s.Assignment); err != nil {
105 return fmt.Errorf("lifecycle %q requires a valid assignment: %w", lifecycle, err)
106 }
107 return nil
108 case WorkerLifecycleDraining, WorkerLifecycleRetired:
109 if s.Assignment == nil {
110 return nil
111 }
112 if err := validateWorkerAssignment(s.Assignment); err != nil {
113 return fmt.Errorf("lifecycle %q has invalid assignment metadata: %w", lifecycle, err)
114 }
115 return nil
116 default:
117 return fmt.Errorf("unknown worker lifecycle %q", lifecycle)
118 }
119}
120
121// Transition validates a lifecycle change and returns the next worker state.
122// When assignment metadata is omitted, the current assignment is carried

Callers 3

TransitionMethod · 0.95
SetSharedStateMethod · 0.80

Calls 2

NormalizedLifecycleMethod · 0.95
validateWorkerAssignmentFunction · 0.85