@@ -40,6 +40,7 @@ import (
4040 historypb "go.temporal.io/api/history/v1"
4141 "go.temporal.io/api/serviceerror"
4242 "go.temporal.io/api/workflowservice/v1"
43+ workflowspb "go.temporal.io/server/api/workflow/v1"
4344
4445 "go.temporal.io/server/api/historyservice/v1"
4546 "go.temporal.io/server/api/matchingservice/v1"
@@ -79,6 +80,16 @@ const (
7980 retryKafkaOperationMaxInterval = 10 * time .Second
8081 retryKafkaOperationExpirationInterval = 30 * time .Second
8182
83+ defaultInitialInterval = time .Second
84+ defaultMaximumIntervalCoefficient = 100.0
85+ defaultBackoffCoefficient = 2.0
86+ defaultMaximumAttempts = 0
87+
88+ initialIntervalInSecondsConfigKey = "InitialIntervalInSeconds"
89+ maximumIntervalCoefficientConfigKey = "MaximumIntervalCoefficient"
90+ backoffCoefficientConfigKey = "BackoffCoefficient"
91+ maximumAttemptsConfigKey = "MaximumAttempts"
92+
8293 contextExpireThreshold = 10 * time .Millisecond
8394
8495 // FailureReasonCompleteResultExceedsLimit is failureReason for complete result exceeds limit
@@ -370,13 +381,13 @@ func SortInt64Slice(slice []int64) {
370381}
371382
372383// EnsureRetryPolicyDefaults ensures the policy subfields, if not explicitly set, are set to the specified defaults
373- func EnsureRetryPolicyDefaults (originalPolicy * commonpb.RetryPolicy , defaultSettings DefaultActivityRetrySettings ) {
384+ func EnsureRetryPolicyDefaults (originalPolicy * commonpb.RetryPolicy , defaultSettings DefaultRetrySettings ) {
374385 if originalPolicy .GetMaximumAttempts () == 0 {
375386 originalPolicy .MaximumAttempts = defaultSettings .MaximumAttempts
376387 }
377388
378389 if timestamp .DurationValue (originalPolicy .GetInitialInterval ()) == 0 {
379- originalPolicy .InitialInterval = timestamp .DurationPtr (time . Duration ( defaultSettings .InitialIntervalInSeconds ) * time . Second )
390+ originalPolicy .InitialInterval = timestamp .DurationPtr (defaultSettings .InitialInterval )
380391 }
381392
382393 if timestamp .DurationValue (originalPolicy .GetMaximumInterval ()) == 0 {
@@ -394,6 +405,7 @@ func ValidateRetryPolicy(policy *commonpb.RetryPolicy) error {
394405 // nil policy is valid which means no retry
395406 return nil
396407 }
408+
397409 if policy .GetMaximumAttempts () == 1 {
398410 // One maximum attempt effectively disable retries. Validating the
399411 // rest of the arguments is pointless
@@ -417,18 +429,61 @@ func ValidateRetryPolicy(policy *commonpb.RetryPolicy) error {
417429 return nil
418430}
419431
432+ func GetDefaultRetryPolicyConfigOptions () map [string ]interface {} {
433+ return map [string ]interface {}{
434+ initialIntervalInSecondsConfigKey : int (defaultInitialInterval .Seconds ()),
435+ maximumIntervalCoefficientConfigKey : defaultMaximumIntervalCoefficient ,
436+ backoffCoefficientConfigKey : defaultBackoffCoefficient ,
437+ maximumAttemptsConfigKey : defaultMaximumAttempts ,
438+ }
439+ }
440+
441+ func FromConfigToDefaultRetrySettings (options map [string ]interface {}) DefaultRetrySettings {
442+ defaultSettings := DefaultRetrySettings {
443+ InitialInterval : defaultInitialInterval ,
444+ MaximumIntervalCoefficient : defaultMaximumIntervalCoefficient ,
445+ BackoffCoefficient : defaultBackoffCoefficient ,
446+ MaximumAttempts : defaultMaximumAttempts ,
447+ }
448+
449+ initialIntervalInSeconds , ok := options [initialIntervalInSecondsConfigKey ]
450+ if ok {
451+ defaultSettings .InitialInterval = time .Duration (initialIntervalInSeconds .(int )) * time .Second
452+ }
453+
454+ maximumIntervalCoefficient , ok := options [maximumIntervalCoefficientConfigKey ]
455+ if ok {
456+ defaultSettings .MaximumIntervalCoefficient = maximumIntervalCoefficient .(float64 )
457+ }
458+
459+ backoffCoefficient , ok := options [backoffCoefficientConfigKey ]
460+ if ok {
461+ defaultSettings .BackoffCoefficient = backoffCoefficient .(float64 )
462+ }
463+
464+ maximumAttempts , ok := options [maximumAttemptsConfigKey ]
465+ if ok {
466+ defaultSettings .MaximumAttempts = int32 (maximumAttempts .(int ))
467+ }
468+
469+ return defaultSettings
470+ }
471+
420472// CreateHistoryStartWorkflowRequest create a start workflow request for history
421473func CreateHistoryStartWorkflowRequest (
422474 namespaceID string ,
423475 startRequest * workflowservice.StartWorkflowExecutionRequest ,
476+ parentExecutionInfo * workflowspb.ParentExecutionInfo ,
477+ now time.Time ,
424478) * historyservice.StartWorkflowExecutionRequest {
425- now := time .Now ()
426479 histRequest := & historyservice.StartWorkflowExecutionRequest {
427480 NamespaceId : namespaceID ,
428481 StartRequest : startRequest ,
429482 ContinueAsNewInitiator : enumspb .CONTINUE_AS_NEW_INITIATOR_WORKFLOW ,
430483 Attempt : 1 ,
484+ ParentExecutionInfo : parentExecutionInfo ,
431485 }
486+
432487 if timestamp .DurationValue (startRequest .GetWorkflowExecutionTimeout ()) > 0 {
433488 deadline := now .Add (timestamp .DurationValue (startRequest .GetWorkflowExecutionTimeout ()))
434489 histRequest .WorkflowExecutionExpirationTime = timestamp .TimePtr (deadline .Round (time .Millisecond ))
0 commit comments