Skip to content

Commit

Permalink
Expose StartDelay in StartWorkflowOptions (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Sep 24, 2023
1 parent 6039cd3 commit ff9b3f4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,14 @@ type (
//
// NOTE: Experimental
EnableEagerStart bool

// StartDelay - Time to wait before dispatching the first workflow task.
// If the workflow gets a signal before the delay, a workflow task will be dispatched and the rest
// of the delay will be ignored. A signal from signal with start will not trigger a workflow task.
// Cannot be set the same time as a CronSchedule.
//
// NOTE: Experimental
StartDelay time.Duration
}

// RetryPolicy defines the retry policy.
Expand Down
8 changes: 8 additions & 0 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,10 @@ func (w *workflowClientInterceptor) ExecuteWorkflow(
eagerExecutor = w.client.eagerDispatcher.applyToRequest(startRequest)
}

if in.Options.StartDelay != 0 {
startRequest.WorkflowStartDelay = &in.Options.StartDelay
}

var response *workflowservice.StartWorkflowExecutionResponse

grpcCtx, cancel := newGRPCContext(ctx, grpcMetricsHandler(
Expand Down Expand Up @@ -1647,6 +1651,10 @@ func (w *workflowClientInterceptor) SignalWithStartWorkflow(
Header: header,
}

if in.Options.StartDelay != 0 {
signalWithStartRequest.WorkflowStartDelay = &in.Options.StartDelay
}

var response *workflowservice.SignalWithStartWorkflowExecutionResponse

// Start creating workflow request.
Expand Down
42 changes: 42 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,48 @@ func (ts *IntegrationTestSuite) TestTimerCancellationConcurrentWithOtherCommandD
ts.NoError(err)
}

func (ts *IntegrationTestSuite) TestStartDelay() {
const wfID = "test-start-delay"
wfOpts := ts.startWorkflowOptions(wfID)
wfOpts.StartDelay = 5 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()

run, err := ts.client.ExecuteWorkflow(ctx, wfOpts, ts.workflows.sleep, time.Second)
ts.NoError(err)

var result int
err = run.Get(ctx, &result)
ts.NoError(err)

iter := ts.client.GetWorkflowHistory(ctx, run.GetID(), run.GetRunID(), false, enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT)
event, err := iter.Next()
ts.NoError(err)
ts.Equal(enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED, event.EventType)
ts.Equal(5*time.Second, *event.GetWorkflowExecutionStartedEventAttributes().GetFirstWorkflowTaskBackoff())
}

func (ts *IntegrationTestSuite) TestStartDelaySignalWithStart() {
const wfID = "test-start-delay-signal-with-start"
wfOpts := ts.startWorkflowOptions(wfID)
wfOpts.StartDelay = 5 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()

run, err := ts.client.SignalWithStartWorkflow(ctx, wfID, "done-signal", true, wfOpts, ts.workflows.WaitSignalReturnParam, 0)
ts.NoError(err)

var result int
err = run.Get(ctx, &result)
ts.NoError(err)

iter := ts.client.GetWorkflowHistory(ctx, run.GetID(), run.GetRunID(), false, enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT)
event, err := iter.Next()
ts.NoError(err)
ts.Equal(enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED, event.EventType)
ts.Equal(5*time.Second, *event.GetWorkflowExecutionStartedEventAttributes().GetFirstWorkflowTaskBackoff())
}

func (ts *IntegrationTestSuite) TestResetWorkflowExecution() {
var originalResult []string
err := ts.executeWorkflow("basic-reset-workflow-execution", ts.workflows.Basic, &originalResult)
Expand Down

0 comments on commit ff9b3f4

Please sign in to comment.