478
479
// handle terminating the current execution (currentWorkflowUpdateAction) and starting a new workflow
480
>
var workflowLease api.WorkflowLease
api.go
481
>
var mutableStateInfo *mutableStateInfo
482
>
// Update current execution and create new execution in one transaction.
483
>
// We already validated that currentWorkflowConditionFailed.RunID is not empty,
484
>
// so the following update won't try to lock the current execution again.
485
>
err = api.GetAndUpdateWorkflowWithNew(
486
>
ctx,
487
>
nil,
488
>
workflowKey,
489
>
currentExecutionUpdateAction,
490
>
func() (historyi.WorkflowContext, historyi.MutableState, error) {
491
>
newMutableState, err := api.NewWorkflowWithSignal(
492
>
s.shardContext,
493
>
s.namespace,
494
>
workflowID,
495
>
newRunID,
496
>
s.request,
497
>
nil)
498
>
if err != nil {
499
return nil, nil, err
500
}
501
502
>
workflowLease, err = s.createOrUpdateLeaseFn(nil, s.shardContext, newMutableState)
api.go
503
>
if err != nil {
504
return nil, nil, err
505
}
506
507
// extract information from MutableState in case this is an eager start
508
>
mutableState := workflowLease.GetMutableState()
api.go
509
>
mutableStateInfo, err = extractMutableStateInfo(ctx, mutableState)
510
>
if err != nil {
511
return nil, nil, err
512
}
513
514
>
return workflowLease.GetContext(), mutableState, nil
api.go
515
},
516
s.shardContext,
517
s.workflowConsistencyChecker,
518
)
519
>
if workflowLease != nil {
api.go
520
>
workflowLease.GetReleaseFn()(err)
521
>
}
522
524
>
case nil:
525
>
if !s.requestEagerStart() {
526
>
return &historyservice.StartWorkflowExecutionResponse{
527
>
RunId: newRunID,
528
>
FirstExecutionRunId: newRunID,
529
>
Started: true,
530
>
Status: enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
531
>
Link: s.generateStartedEventRefLink(newRunID),
532
>
}, StartNew, nil
533
>
}
534
events, err := s.getWorkflowHistory(ctx, mutableStateInfo)
535
if err != nil {