Skip to content

Commit 4485e83

Browse files
authored
ChildWorkflow defaults to workflow run timeout specified by parent (#566)
1 parent d527d1c commit 4485e83

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

host/integration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,8 @@ func (s *integrationSuite) TestChildWorkflowExecution() {
18451845
s.Equal(header, childStartedEvent.GetWorkflowExecutionStartedEventAttributes().Header)
18461846
s.Equal(memo, childStartedEvent.GetWorkflowExecutionStartedEventAttributes().GetMemo())
18471847
s.Equal(searchAttr, childStartedEvent.GetWorkflowExecutionStartedEventAttributes().GetSearchAttributes())
1848+
s.Equal(int32(315360000), childStartedEvent.GetWorkflowExecutionStartedEventAttributes().GetWorkflowExecutionTimeoutSeconds())
1849+
s.Equal(int32(200), childStartedEvent.GetWorkflowExecutionStartedEventAttributes().GetWorkflowRunTimeoutSeconds())
18481850

18491851
// Process ChildExecution completed event and complete parent execution
18501852
_, err = pollerParent.PollAndProcessWorkflowTask(false, false)

service/history/commandChecker.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
type (
5252
commandAttrValidator struct {
5353
namespaceCache cache.NamespaceCache
54+
config *Config
5455
maxIDLengthLimit int
5556
searchAttributesValidator *validator.SearchAttributesValidator
5657
}
@@ -84,6 +85,7 @@ func newCommandAttrValidator(
8485
) *commandAttrValidator {
8586
return &commandAttrValidator{
8687
namespaceCache: namespaceCache,
88+
config: config,
8789
maxIDLengthLimit: config.MaxIDLengthLimit(),
8890
searchAttributesValidator: validator.NewSearchAttributesValidator(
8991
logger,
@@ -546,6 +548,7 @@ func (v *commandAttrValidator) validateContinueAsNewWorkflowExecutionAttributes(
546548
func (v *commandAttrValidator) validateStartChildExecutionAttributes(
547549
namespaceID string,
548550
targetNamespaceID string,
551+
targetNamespace string,
549552
attributes *commandpb.StartChildWorkflowExecutionCommandAttributes,
550553
parentInfo *persistence.WorkflowExecutionInfo,
551554
) error {
@@ -596,15 +599,11 @@ func (v *commandAttrValidator) validateStartChildExecutionAttributes(
596599
}
597600
attributes.TaskQueue = taskQueue
598601

599-
// Inherit workflow timeout from parent workflow execution if not provided on command
600-
if attributes.GetWorkflowExecutionTimeoutSeconds() <= 0 {
601-
attributes.WorkflowExecutionTimeoutSeconds = parentInfo.WorkflowExecutionTimeout
602-
}
602+
attributes.WorkflowExecutionTimeoutSeconds = getWorkflowExecutionTimeout(targetNamespace,
603+
attributes.GetWorkflowExecutionTimeoutSeconds(), v.config)
603604

604-
// Inherit workflow timeout from parent workflow execution if not provided on command
605-
if attributes.GetWorkflowRunTimeoutSeconds() <= 0 {
606-
attributes.WorkflowRunTimeoutSeconds = parentInfo.WorkflowRunTimeout
607-
}
605+
attributes.WorkflowRunTimeoutSeconds = getWorkflowRunTimeout(targetNamespace,
606+
attributes.GetWorkflowRunTimeoutSeconds(), attributes.GetWorkflowExecutionTimeoutSeconds(), v.config)
608607

609608
// Inherit workflow task timeout from parent workflow execution if not provided on command
610609
if attributes.GetWorkflowTaskTimeoutSeconds() <= 0 {

service/history/historyEngine.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,13 +2657,7 @@ func (e *historyEngineImpl) overrideStartWorkflowExecutionRequest(
26572657
metricsScope int,
26582658
) {
26592659
namespace := namespaceEntry.GetInfo().Name
2660-
2661-
executionTimeoutSeconds := request.GetWorkflowExecutionTimeoutSeconds()
2662-
if executionTimeoutSeconds == 0 {
2663-
executionTimeoutSeconds = convert.Int32Ceil(e.config.DefaultWorkflowExecutionTimeout(namespace).Seconds())
2664-
}
2665-
maxWorkflowExecutionTimeout := convert.Int32Ceil(e.config.MaxWorkflowExecutionTimeout(namespace).Seconds())
2666-
executionTimeoutSeconds = common.MinInt32(executionTimeoutSeconds, maxWorkflowExecutionTimeout)
2660+
executionTimeoutSeconds := getWorkflowExecutionTimeout(namespace, request.GetWorkflowExecutionTimeoutSeconds(), e.config)
26672661
if executionTimeoutSeconds != request.GetWorkflowExecutionTimeoutSeconds() {
26682662
request.WorkflowExecutionTimeoutSeconds = executionTimeoutSeconds
26692663
e.metricsClient.Scope(
@@ -2672,13 +2666,8 @@ func (e *historyEngineImpl) overrideStartWorkflowExecutionRequest(
26722666
).IncCounter(metrics.WorkflowExecutionTimeoutOverrideCount)
26732667
}
26742668

2675-
runTimeoutSeconds := request.GetWorkflowRunTimeoutSeconds()
2676-
if runTimeoutSeconds == 0 {
2677-
runTimeoutSeconds = convert.Int32Ceil(e.config.DefaultWorkflowRunTimeout(namespace).Seconds())
2678-
}
2679-
maxWorkflowRunTimeout := convert.Int32Ceil(e.config.MaxWorkflowRunTimeout(namespace).Seconds())
2680-
runTimeoutSeconds = common.MinInt32(runTimeoutSeconds, maxWorkflowRunTimeout)
2681-
runTimeoutSeconds = common.MinInt32(runTimeoutSeconds, executionTimeoutSeconds)
2669+
runTimeoutSeconds := getWorkflowRunTimeout(namespace, request.GetWorkflowRunTimeoutSeconds(),
2670+
executionTimeoutSeconds, e.config)
26822671
if runTimeoutSeconds != request.GetWorkflowRunTimeoutSeconds() {
26832672
request.WorkflowRunTimeoutSeconds = runTimeoutSeconds
26842673
e.metricsClient.Scope(

service/history/workflowExecutionUtil.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"go.temporal.io/api/serviceerror"
3232

3333
"go.temporal.io/server/common"
34+
"go.temporal.io/server/common/convert"
3435
)
3536

3637
type workflowContext interface {
@@ -222,3 +223,26 @@ func terminateWorkflow(
222223
)
223224
return err
224225
}
226+
227+
func getWorkflowExecutionTimeout(namespace string, requestedTimeout int32, serviceConfig *Config) int32 {
228+
executionTimeoutSeconds := requestedTimeout
229+
if executionTimeoutSeconds == 0 {
230+
executionTimeoutSeconds = convert.Int32Ceil(serviceConfig.DefaultWorkflowExecutionTimeout(namespace).Seconds())
231+
}
232+
maxWorkflowExecutionTimeout := convert.Int32Ceil(serviceConfig.MaxWorkflowExecutionTimeout(namespace).Seconds())
233+
executionTimeoutSeconds = common.MinInt32(executionTimeoutSeconds, maxWorkflowExecutionTimeout)
234+
235+
return executionTimeoutSeconds
236+
}
237+
238+
func getWorkflowRunTimeout(namespace string, requestedTimeout, executionTimeout int32, serviceConfig *Config) int32 {
239+
runTimeoutSeconds := requestedTimeout
240+
if runTimeoutSeconds == 0 {
241+
runTimeoutSeconds = convert.Int32Ceil(serviceConfig.DefaultWorkflowRunTimeout(namespace).Seconds())
242+
}
243+
maxWorkflowRunTimeout := convert.Int32Ceil(serviceConfig.MaxWorkflowRunTimeout(namespace).Seconds())
244+
runTimeoutSeconds = common.MinInt32(runTimeoutSeconds, maxWorkflowRunTimeout)
245+
runTimeoutSeconds = common.MinInt32(runTimeoutSeconds, executionTimeout)
246+
247+
return runTimeoutSeconds
248+
}

service/history/workflowTaskHandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,15 @@ func (handler *workflowTaskHandlerImpl) handleCommandStartChildWorkflow(
726726

727727
executionInfo := handler.mutableState.GetExecutionInfo()
728728
namespaceID := executionInfo.NamespaceID
729+
parentNamespace := handler.namespaceEntry.GetInfo().GetName()
729730
targetNamespaceID := namespaceID
731+
targetNamespace := parentNamespace
730732
if attr.GetNamespace() != "" {
731733
targetNamespaceEntry, err := handler.namespaceCache.GetNamespace(attr.GetNamespace())
732734
if err != nil {
733735
return serviceerror.NewInternal(fmt.Sprintf("Unable to schedule child execution across namespace %v.", attr.GetNamespace()))
734736
}
737+
targetNamespace = targetNamespaceEntry.GetInfo().Name
735738
targetNamespaceID = targetNamespaceEntry.GetInfo().Id
736739
}
737740

@@ -740,6 +743,7 @@ func (handler *workflowTaskHandlerImpl) handleCommandStartChildWorkflow(
740743
return handler.attrValidator.validateStartChildExecutionAttributes(
741744
namespaceID,
742745
targetNamespaceID,
746+
targetNamespace,
743747
attr,
744748
executionInfo,
745749
)

0 commit comments

Comments
 (0)