Skip to content

Commit

Permalink
Support CLI Delay Start (cadence-workflow#4097)
Browse files Browse the repository at this point in the history
* add delayed start support

* Address comments

* Add delay start support to cli

* Add integration test
  • Loading branch information
demirkayaender authored Apr 1, 2021
1 parent d3d4561 commit 7bd9105
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 97 deletions.
148 changes: 140 additions & 8 deletions .gen/go/shared/shared.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions common/types/mapper/thrift/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -5039,6 +5039,7 @@ func FromStartWorkflowExecutionRequest(t *types.StartWorkflowExecutionRequest) *
Memo: FromMemo(t.Memo),
SearchAttributes: FromSearchAttributes(t.SearchAttributes),
Header: FromHeader(t.Header),
DelayStartSeconds: t.DelayStartSeconds,
}
}

Expand All @@ -5063,6 +5064,7 @@ func ToStartWorkflowExecutionRequest(t *shared.StartWorkflowExecutionRequest) *t
Memo: ToMemo(t.Memo),
SearchAttributes: ToSearchAttributes(t.SearchAttributes),
Header: ToHeader(t.Header),
DelayStartSeconds: t.DelayStartSeconds,
}
}

Expand Down
27 changes: 27 additions & 0 deletions common/types/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -7518,6 +7518,7 @@ type SignalWithStartWorkflowExecutionRequest struct {
Memo *Memo `json:"memo,omitempty"`
SearchAttributes *SearchAttributes `json:"searchAttributes,omitempty"`
Header *Header `json:"header,omitempty"`
DelayStartSeconds *int32 `json:"delayStartSeconds,omitempty"`
}

// GetDomain is an internal getter (TBD...)
Expand Down Expand Up @@ -7576,6 +7577,14 @@ func (v *SignalWithStartWorkflowExecutionRequest) GetTaskStartToCloseTimeoutSeco
return
}

// GetDelayStartSeconds is an internal getter (TBD...)
func (v *SignalWithStartWorkflowExecutionRequest) GetDelayStartSeconds() (o int32) {
if v != nil && v.DelayStartSeconds != nil {
return *v.DelayStartSeconds
}
return
}

// GetIdentity is an internal getter (TBD...)
func (v *SignalWithStartWorkflowExecutionRequest) GetIdentity() (o string) {
if v != nil {
Expand Down Expand Up @@ -7955,6 +7964,7 @@ type StartChildWorkflowExecutionInitiatedEventAttributes struct {
Header *Header `json:"header,omitempty"`
Memo *Memo `json:"memo,omitempty"`
SearchAttributes *SearchAttributes `json:"searchAttributes,omitempty"`
DelayStartSeconds *int32 `json:"delayStartSeconds,omitempty"`
}

// GetDomain is an internal getter (TBD...)
Expand Down Expand Up @@ -8013,6 +8023,14 @@ func (v *StartChildWorkflowExecutionInitiatedEventAttributes) GetTaskStartToClos
return
}

// GetDelayStartSeconds is an internal getter (TBD...)
func (v *StartChildWorkflowExecutionInitiatedEventAttributes) GetDelayStartSeconds() (o int32) {
if v != nil && v.DelayStartSeconds != nil {
return *v.DelayStartSeconds
}
return
}

// GetParentClosePolicy is an internal getter (TBD...)
func (v *StartChildWorkflowExecutionInitiatedEventAttributes) GetParentClosePolicy() (o ParentClosePolicy) {
if v != nil && v.ParentClosePolicy != nil {
Expand Down Expand Up @@ -8146,6 +8164,7 @@ type StartWorkflowExecutionRequest struct {
Memo *Memo `json:"memo,omitempty"`
SearchAttributes *SearchAttributes `json:"searchAttributes,omitempty"`
Header *Header `json:"header,omitempty"`
DelayStartSeconds *int32 `json:"delayStartSeconds,omitempty"`
}

// GetDomain is an internal getter (TBD...)
Expand Down Expand Up @@ -8204,6 +8223,14 @@ func (v *StartWorkflowExecutionRequest) GetTaskStartToCloseTimeoutSeconds() (o i
return
}

// GetDelayStartSeconds is an internal getter (TBD...)
func (v *StartWorkflowExecutionRequest) GetDelayStartSeconds() (o int32) {
if v != nil && v.DelayStartSeconds != nil {
return *v.DelayStartSeconds
}
return
}

// GetIdentity is an internal getter (TBD...)
func (v *StartWorkflowExecutionRequest) GetIdentity() (o string) {
if v != nil {
Expand Down
17 changes: 14 additions & 3 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var (
ErrContextTimeoutTooShort = &types.BadRequestError{Message: "Context timeout is too short."}
// ErrContextTimeoutNotSet is error for not setting a context timeout when calling a long poll API
ErrContextTimeoutNotSet = &types.BadRequestError{Message: "Context timeout is not set."}
ErrDelayStartSeconds = &types.BadRequestError{Message: "Conflicting inputs: both DelayStartSeconds and Cron schedule is set"}
)

// AwaitWaitGroup calls Wait on the given wait
Expand Down Expand Up @@ -421,12 +422,22 @@ func CreateHistoryStartWorkflowRequest(
domainID string,
startRequest *types.StartWorkflowExecutionRequest,
now time.Time,
) *types.HistoryStartWorkflowExecutionRequest {
) (*types.HistoryStartWorkflowExecutionRequest, error) {
histRequest := &types.HistoryStartWorkflowExecutionRequest{
DomainUUID: domainID,
StartRequest: startRequest,
}
firstDecisionTaskBackoffSeconds := backoff.GetBackoffForNextScheduleInSeconds(startRequest.GetCronSchedule(), now, now)

firstDecisionTaskBackoffSeconds := backoff.GetBackoffForNextScheduleInSeconds(
startRequest.GetCronSchedule(), now, now)
delayStartSeconds := startRequest.GetDelayStartSeconds()
if delayStartSeconds > 0 && firstDecisionTaskBackoffSeconds > 0 {
return nil, ErrDelayStartSeconds
}
if delayStartSeconds > 0 {
firstDecisionTaskBackoffSeconds = delayStartSeconds
}

histRequest.FirstDecisionTaskBackoffSeconds = Int32Ptr(firstDecisionTaskBackoffSeconds)

if startRequest.RetryPolicy != nil && startRequest.RetryPolicy.GetExpirationIntervalInSeconds() > 0 {
Expand All @@ -436,7 +447,7 @@ func CreateHistoryStartWorkflowRequest(
histRequest.ExpirationTimestamp = Int64Ptr(deadline.Round(time.Millisecond).UnixNano())
}

return histRequest
return histRequest, nil
}

// CheckEventBlobSizeLimit checks if a blob data exceeds limits. It logs a warning if it exceeds warnLimit,
Expand Down
25 changes: 23 additions & 2 deletions common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,33 @@ func TestCreateHistoryStartWorkflowRequest_ExpirationTimeWithCron(t *testing.T)
CronSchedule: "@every 300s",
}
now := time.Now()
startRequest := CreateHistoryStartWorkflowRequest(domainID, request, now)
startRequest, _ := CreateHistoryStartWorkflowRequest(domainID, request, now)
require.NotNil(t, startRequest)

expirationTime := startRequest.GetExpirationTimestamp()
require.NotNil(t, expirationTime)
require.True(t, time.Unix(0, expirationTime).Sub(now) > 60*time.Second)
}

func TestCreateHistoryStartWorkflowRequest_DelayStart(t *testing.T) {
domainID := uuid.New()
request := &types.StartWorkflowExecutionRequest{
RetryPolicy: &types.RetryPolicy{
InitialIntervalInSeconds: 60,
ExpirationIntervalInSeconds: 60,
},
DelayStartSeconds: Int32Ptr(100),
}
now := time.Now()
startRequest, _ := CreateHistoryStartWorkflowRequest(domainID, request, now)
require.NotNil(t, startRequest)

expirationTime := startRequest.GetExpirationTimestamp()
require.NotNil(t, expirationTime)
require.True(t, time.Unix(0, expirationTime).Sub(now) > (100+60)*time.Second)
require.True(t, time.Unix(0, expirationTime).Sub(now) < (100+65)*time.Second)
}

func TestCreateHistoryStartWorkflowRequest_ExpirationTimeWithoutCron(t *testing.T) {
domainID := uuid.New()
request := &types.StartWorkflowExecutionRequest{
Expand All @@ -113,7 +133,8 @@ func TestCreateHistoryStartWorkflowRequest_ExpirationTimeWithoutCron(t *testing.
},
}
now := time.Now()
startRequest := CreateHistoryStartWorkflowRequest(domainID, request, now)
startRequest, _ := CreateHistoryStartWorkflowRequest(domainID, request, now)
require.NotNil(t, startRequest)

expirationTime := startRequest.GetExpirationTimestamp()
require.NotNil(t, expirationTime)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
go.opencensus.io v0.22.5 // indirect
go.uber.org/atomic v1.5.1
go.uber.org/cadence v0.16.0
go.uber.org/cadence v0.16.1-0.20210330222409-fcc703e94e2f
go.uber.org/fx v1.10.0
go.uber.org/multierr v1.4.0
go.uber.org/thriftrw v1.25.0
Expand Down
Loading

0 comments on commit 7bd9105

Please sign in to comment.