workflow.go ×21

Frontier kind: Code frontier

unlabeled · c_6c07a40566f0

296 tests · 2738 LOC · 132 files · introduces 0 tests · 161 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
30 ranges161 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
403 ranges2738 lines · 132 files · Browse complete extent
All tests (intent)
296 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: 161 introduced LOC across 30 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/worker/workerdeployment/workflow.go 127 introduced LOC · 21 ranges

Open complete file

62 // In steady state (i.e. absence of ongoing updates or signals) the wf should only have
63 // a single wft in the history.
64 > func Workflow(ctx workflow.Context, unsafeWorkflowVersionGetter func() DeploymentWorkflowVersion, unsafeMaxVersion func() int, args *deploymentspb.WorkerDeploymentWorkflowArgs) error { workflow.go
65 > workflowRunner := &WorkflowRunner{
66 > WorkerDeploymentWorkflowArgs: args,
67 > workflowVersion: getWorkflowVersion(ctx, unsafeWorkflowVersionGetter),
68 > a: nil,
69 > logger: sdklog.With(workflow.GetLogger(ctx), "wf-namespace", args.NamespaceName),
70 > metrics: workflow.GetMetricsHandler(ctx).WithTags(map[string]string{"namespace": args.NamespaceName}),
71 > lock: workflow.NewMutex(ctx),
72 > unsafeMaxVersion: unsafeMaxVersion,
73 > signalHandler: &SignalHandler{
74 > signalSelector: workflow.NewSelector(ctx),
75 > },
76 > }
77 >
78 > return workflowRunner.run(ctx)
79 > }
80
81 func getWorkflowVersion(ctx workflow.Context, unsafeWorkflowVersionGetter func() DeploymentWorkflowVersion) DeploymentWorkflowVersion {
97 }
98
99 > func (d *WorkflowRunner) listenToSignals(ctx workflow.Context) { workflow.go
100 > forceCANSignalChannel := workflow.GetSignalChannel(ctx, ForceCANSignalName)
101 > syncVersionSummaryChannel := workflow.GetSignalChannel(ctx, SyncVersionSummarySignal)
102 > propagationCompleteChannel := workflow.GetSignalChannel(ctx, PropagationCompleteSignal)
103 >
104 > d.signalHandler.signalSelector.AddReceive(forceCANSignalChannel, func(c workflow.ReceiveChannel, more bool) {
105 d.signalHandler.processingSignals++
106 defer func() { d.signalHandler.processingSignals-- }()
115 }
116 })
117 > d.signalHandler.signalSelector.AddReceive(syncVersionSummaryChannel, func(c workflow.ReceiveChannel, more bool) { workflow.go
118 d.signalHandler.processingSignals++
119 defer func() { d.signalHandler.processingSignals-- }()
123 d.setStateChanged()
124 })
125 > d.signalHandler.signalSelector.AddReceive(propagationCompleteChannel, func(c workflow.ReceiveChannel, more bool) { workflow.go
126 d.signalHandler.processingSignals++
127 defer func() { d.signalHandler.processingSignals-- }()
133
134 // Keep waiting for signals, when it's time to CaN the main goroutine will exit.
135 > for { workflow.go
136 > d.signalHandler.signalSelector.Select(ctx)
137 > }
138 }
139
223 }
224
225 > func (d *WorkflowRunner) run(ctx workflow.Context) error { workflow.go
226 > // TODO(carlydf): remove verbose logging
227 > d.logger.Info("Raw workflow state at start",
228 > "state_nil", d.State == nil,
229 > "create_time_nil", d.GetState().GetCreateTime() == nil,
230 > "routing_config_nil", d.GetState().GetRoutingConfig() == nil,
231 > "raw_state", d.State,
232 > "workflow_id", workflow.GetInfo(ctx).WorkflowExecution.ID,
233 > "run_id", workflow.GetInfo(ctx).WorkflowExecution.RunID)
234 >
235 > if d.GetState().GetCreateTime() == nil ||
236 > d.GetState().GetRoutingConfig() == nil ||
237 > d.GetState().GetConflictToken() == nil {
238 if d.State == nil {
239 d.State = &deploymentspb.WorkerDeploymentLocalState{}
256 d.metrics.Counter(metrics.WorkerDeploymentCreated.Name()).Inc(1)
257 }
258 > if d.State.Versions == nil { workflow.go
259 d.State.Versions = make(map[string]*deploymentspb.WorkerDeploymentVersionSummary)
260 }
261
262 // TODO(carlydf): remove verbose logging
263 > d.logger.Info("Starting workflow run", workflow.go
264 > "create_time", d.State.GetCreateTime(),
265 > "routing_config", d.State.GetRoutingConfig(),
266 > //nolint:staticcheck // SA1019: worker versioning v0.31
267 > "current_version", d.State.GetRoutingConfig().GetCurrentVersion(),
268 > //nolint:staticcheck // SA1019: worker versioning v0.31
269 > "ramping_version", d.State.GetRoutingConfig().GetRampingVersion())
270 >
271 > err := workflow.SetQueryHandler(ctx, QueryDescribeDeployment, func() (*deploymentspb.QueryDescribeWorkerDeploymentResponse, error) {
272 if d.deleteDeployment {
273 return nil, errors.New(errDeploymentDeleted)
277 }, nil
278 })
279 > if err != nil { workflow.go
280 d.logger.Info("SetQueryHandler failed for WorkerDeployment workflow with error: " + err.Error())
281 return err
282 }
283
284 > err = workflow.SetQueryHandler(ctx, QueryCreateRequestID, func() (*deploymentspb.CreateRequestIDQueryResponse, error) { workflow.go
285 if d.deleteDeployment {
286 return nil, errors.New(errDeploymentDeleted)
291 }, nil
292 })
293 > if err != nil { workflow.go
294 d.logger.Info("SetQueryHandler failed for WorkerDeployment create request-id query with error: " + err.Error())
295 return err
296 }
297
298 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
299 > ctx,
300 > CreateWorkerDeployment,
301 > d.handleCreateWorkerDeployment,
302 > workflow.UpdateHandlerOptions{
303 > Validator: d.validateCreateWorkerDeployment,
304 > },
305 > ); err != nil {
306 return err
307 }
308
309 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
310 > ctx,
311 > CreateWorkerDeploymentVersion,
312 > d.handleCreateWorkerDeploymentVersion,
313 > workflow.UpdateHandlerOptions{
314 > Validator: d.validateCreateWorkerDeploymentVersion,
315 > },
316 > ); err != nil {
317 return err
318 }
319
320 > if err := workflow.SetUpdateHandler( workflow.go
321 > ctx,
322 > RegisterWorkerInWorkerDeployment,
323 > d.handleRegisterWorker,
324 > ); err != nil {
325 return err
326 }
327
328 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
329 > ctx,
330 > SetCurrentVersion,
331 > d.handleSetCurrent,
332 > workflow.UpdateHandlerOptions{
333 > Validator: d.validateSetCurrent,
334 > },
335 > ); err != nil {
336 return err
337 }
338
339 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
340 > ctx,
341 > SetRampingVersion,
342 > d.handleSetRampingVersion,
343 > workflow.UpdateHandlerOptions{
344 > Validator: d.validateSetRampingVersion,
345 > },
346 > ); err != nil {
347 return err
348 }
349
350 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
351 > ctx,
352 > SetManagerIdentity,
353 > d.handleSetManager,
354 > workflow.UpdateHandlerOptions{
355 > Validator: d.validateSetManager,
356 > },
357 > ); err != nil {
358 return err
359 }
360
361 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
362 > ctx,
363 > DeleteVersion,
364 > d.handleDeleteVersion,
365 > workflow.UpdateHandlerOptions{
366 > Validator: d.validateDeleteVersion,
367 > },
368 > ); err != nil {
369 return err
370 }
371
372 > if err := workflow.SetUpdateHandlerWithOptions( workflow.go
373 > ctx,
374 > DeleteDeployment,
375 > d.handleDeleteDeployment,
376 > workflow.UpdateHandlerOptions{
377 > Validator: d.validateDeleteDeployment,
378 > },
379 > ); err != nil {
380 return err
381 }
382
383 // Listen to signals in a different goroutine to make business logic clearer
384 > workflow.Go(ctx, d.listenToSignals) workflow.go
385 >
386 > // Wait until we can continue as new or are cancelled. The workflow will continue-as-new iff
387 > // there are no pending updates/signals and the state has changed.
388 > err = workflow.Await(ctx, func() bool {
389 > canContinue := d.deleteDeployment || // deployment is deleted -> it's ok to drop all signals and updates.
390 > // There is no pending signal or update, but the state is dirty or forceCaN is requested:
391 > (!d.signalHandler.signalSelector.HasPending() && d.signalHandler.processingSignals == 0 && workflow.AllHandlersFinished(ctx) &&
392 > (d.forceCAN || d.stateChanged || workflow.GetInfo(ctx).GetContinueAsNewSuggested()))
393 >
394 > // TODO(carlydf): remove verbose logging
395 > if canContinue {
396 d.logger.Info("Workflow can continue as new",
397 "workflow_id", workflow.GetInfo(ctx).WorkflowExecution.ID,
405 "routing_config", d.State.GetRoutingConfig())
406 }
407 > return canContinue workflow.go
408 })
409 if err != nil {
go.temporal.io/server/api/deployment/v1/message.pb.go 34 introduced LOC · 9 ranges

Open complete file

613 }
614
615 > func (x *WorkerDeploymentWorkflowArgs) Reset() { message.pb.go
616 > *x = WorkerDeploymentWorkflowArgs{}
617 > mi := &file_temporal_server_api_deployment_v1_message_proto_msgTypes[6]
618 > ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
619 > ms.StoreMessageInfo(mi)
620 > }
621
622 func (x *WorkerDeploymentWorkflowArgs) String() string {
626 func (*WorkerDeploymentWorkflowArgs) ProtoMessage() {}
627
628 > func (x *WorkerDeploymentWorkflowArgs) ProtoReflect() protoreflect.Message { message.pb.go
629 > mi := &file_temporal_server_api_deployment_v1_message_proto_msgTypes[6]
630 > if x != nil {
631 > ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
632 > if ms.LoadMessageInfo() == nil {
633 > ms.StoreMessageInfo(mi)
634 > }
635 > return ms
636 }
637 return mi.MessageOf(x)
664 }
665
666 > func (x *WorkerDeploymentWorkflowArgs) GetState() *WorkerDeploymentLocalState { message.pb.go
667 > if x != nil {
668 > return x.State
669 > }
670 return nil
671 }
705 func (*WorkerDeploymentLocalState) ProtoMessage() {}
706
707 > func (x *WorkerDeploymentLocalState) ProtoReflect() protoreflect.Message { message.pb.go
708 > mi := &file_temporal_server_api_deployment_v1_message_proto_msgTypes[7]
709 > if x != nil {
710 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
711 if ms.LoadMessageInfo() == nil {
714 return ms
715 }
716 > return mi.MessageOf(x) message.pb.go
717 }
718
722 }
723
724 > func (x *WorkerDeploymentLocalState) GetCreateTime() *timestamppb.Timestamp { message.pb.go
725 > if x != nil {
726 > return x.CreateTime
727 > }
728 return nil
729 }
730
731 > func (x *WorkerDeploymentLocalState) GetRoutingConfig() *v11.RoutingConfig { message.pb.go
732 > if x != nil {
733 > return x.RoutingConfig
734 > }
735 return nil
736 }
806 func (*PropagatingRevisions) ProtoMessage() {}
807
808 > func (x *PropagatingRevisions) ProtoReflect() protoreflect.Message { message.pb.go
809 > mi := &file_temporal_server_api_deployment_v1_message_proto_msgTypes[8]
810 > if x != nil {
811 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
812 if ms.LoadMessageInfo() == nil {
815 return ms
816 }
817 > return mi.MessageOf(x) message.pb.go
818 }
819