@@ -99,16 +99,32 @@ func NewWorkflowWithSignal(
99
99
return nil , err
100
100
}
101
101
}
102
-
102
+ requestEagerExecution := startRequest . StartRequest . GetRequestEagerExecution ()
103
103
// Generate first workflow task event if not child WF and no first workflow task backoff
104
- if err := GenerateFirstWorkflowTask (
104
+ scheduledEventID , err := GenerateFirstWorkflowTask (
105
105
newMutableState ,
106
106
startRequest .ParentExecutionInfo ,
107
107
startEvent ,
108
- ); err != nil {
108
+ requestEagerExecution ,
109
+ )
110
+ if err != nil {
109
111
return nil , err
110
112
}
111
113
114
+ // If first workflow task should back off (e.g. cron or workflow retry) a workflow task will not be scheduled.
115
+ if requestEagerExecution && newMutableState .HasPendingWorkflowTask () {
116
+ _ , _ , err = newMutableState .AddWorkflowTaskStartedEvent (
117
+ scheduledEventID ,
118
+ startRequest .StartRequest .RequestId ,
119
+ startRequest .StartRequest .TaskQueue ,
120
+ startRequest .StartRequest .Identity ,
121
+ )
122
+ if err != nil {
123
+ // Unable to add WorkflowTaskStarted event to history
124
+ return nil , err
125
+ }
126
+ }
127
+
112
128
newWorkflowContext := workflow .NewContext (
113
129
shard ,
114
130
definition .NewWorkflowKey (
@@ -146,17 +162,13 @@ func GenerateFirstWorkflowTask(
146
162
mutableState workflow.MutableState ,
147
163
parentInfo * workflowspb.ParentExecutionInfo ,
148
164
startEvent * historypb.HistoryEvent ,
149
- ) error {
150
-
165
+ bypassTaskGeneration bool ,
166
+ ) ( int64 , error ) {
151
167
if parentInfo == nil {
152
168
// WorkflowTask is only created when it is not a Child Workflow and no backoff is needed
153
- if err := mutableState .AddFirstWorkflowTaskScheduled (
154
- startEvent ,
155
- ); err != nil {
156
- return err
157
- }
169
+ return mutableState .AddFirstWorkflowTaskScheduled (startEvent , bypassTaskGeneration )
158
170
}
159
- return nil
171
+ return 0 , nil
160
172
}
161
173
162
174
func NewWorkflowVersionCheck (
@@ -272,7 +284,6 @@ func ValidateStartWorkflowExecutionRequest(
272
284
if err := common .ValidateRetryPolicy (request .RetryPolicy ); err != nil {
273
285
return err
274
286
}
275
-
276
287
if err := ValidateStart (
277
288
ctx ,
278
289
shard ,
0 commit comments