291
}, nil
292
})
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
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
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",
workflow.go
397
>
"workflow_id", workflow.GetInfo(ctx).WorkflowExecution.ID,
398
>
"run_id", workflow.GetInfo(ctx).WorkflowExecution.RunID,
399
>
"delete_deployment", d.deleteDeployment,
400
>
"has_pending_signals", d.signalHandler.signalSelector.HasPending(),
401
>
"processing_signals", d.signalHandler.processingSignals,
402
>
"all_handlers_finished", workflow.AllHandlersFinished(ctx),
403
>
"force_can", d.forceCAN,
404
>
"state_changed", d.stateChanged,
405
>
"routing_config", d.State.GetRoutingConfig())
406
>
}
408
})
410
return err
411
}
412
414
return nil
415
}
416
417
// TODO(carlydf): remove verbose logging
418
>
d.logger.Info("Continuing workflow as new",
workflow.go
419
>
"create_time", d.State.GetCreateTime(),
420
>
"routing_config", d.State.GetRoutingConfig(),
421
>
//nolint:staticcheck // SA1019: worker versioning v0.31
422
>
"current_version", d.State.GetRoutingConfig().GetCurrentVersion(),
423
>
//nolint:staticcheck // SA1019: worker versioning v0.31
424
>
"ramping_version", d.State.GetRoutingConfig().GetRampingVersion(),
425
>
"state_changed", d.stateChanged,
426
>
"force_can", d.forceCAN,
427
>
"workflow_id", workflow.GetInfo(ctx).WorkflowExecution.ID,
428
>
"run_id", workflow.GetInfo(ctx).WorkflowExecution.RunID)
429
>
430
>
// We perform a continue-as-new after each update and signal is handled to ensure compatibility
431
>
// even if the server rolls back to a previous minor version. By continuing-as-new,
432
>
// we pass the current state as input to the next workflow execution, resulting in a new
433
>
// workflow history with just two initial events. This minimizes the risk of NDE (Non-Deterministic Execution)
434
>
// errors during server rollbacks.
435
>
436
>
// Apply override state if provided during force-CaN
437
>
if d.overrideState != nil {
438
d.State = d.overrideState
439
}
440
>
return workflow.NewContinueAsNewError(ctx, WorkerDeploymentWorkflowType, d.WorkerDeploymentWorkflowArgs)
workflow.go
441
}
442