Skip to content

Commit d675887

Browse files
committed
populate task for empty polls instead
1 parent 9783bf3 commit d675887

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

internal/internal_poller_autoscaler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ func (m *pollerUsageEstimator) CollectUsage(data interface{}) error {
174174
func isTaskEmpty(task interface{}) (bool, error) {
175175
switch t := task.(type) {
176176
case *workflowTask:
177-
return t == nil || t.task == nil, nil
177+
return t == nil || isEmptyDecisionTask(t.task), nil
178178
case *activityTask:
179-
return t == nil || t.task == nil, nil
179+
return t == nil || isEmptyActivityTask(t.task), nil
180180
case *localActivityTask:
181181
return t == nil || t.workflowTask == nil, nil
182182
default:

internal/internal_task_handlers.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type (
7575
// workflowTask wraps a decision task.
7676
workflowTask struct {
7777
task *s.PollForDecisionTaskResponse
78-
autoConfigHint *s.AutoConfigHint
7978
historyIterator HistoryIterator
8079
doneCh chan struct{}
8180
laResultCh chan *localActivityResult
@@ -84,7 +83,6 @@ type (
8483
// activityTask wraps a activity task.
8584
activityTask struct {
8685
task *s.PollForActivityTaskResponse
87-
autoConfigHint *s.AutoConfigHint
8886
pollStartTime time.Time
8987
}
9088

@@ -746,7 +744,7 @@ func (wth *workflowTaskHandlerImpl) ProcessWorkflowTask(
746744
workflowTask *workflowTask,
747745
heartbeatFunc decisionHeartbeatFunc,
748746
) (completeRequest interface{}, errRet error) {
749-
if workflowTask == nil || workflowTask.task == nil {
747+
if workflowTask == nil || isEmptyDecisionTask(workflowTask.task) {
750748
return nil, errors.New("nil workflow task provided")
751749
}
752750
task := workflowTask.task

internal/internal_task_pollers.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,7 @@ func (wtp *workflowTaskPoller) poll(ctx context.Context) (interface{}, error) {
848848
if response == nil || len(response.TaskToken) == 0 {
849849
wtp.metricsScope.Counter(metrics.DecisionPollNoTaskCounter).Inc(1)
850850
wtp.updateBacklog(request.TaskList.GetKind(), 0)
851-
return &workflowTask{
852-
autoConfigHint: response.GetAutoConfigHint(),
853-
}, nil
851+
return &workflowTask{task: response}, nil
854852
}
855853

856854
wtp.updateBacklog(request.TaskList.GetKind(), response.GetBacklogCountHint())
@@ -910,7 +908,6 @@ func (wtp *workflowTaskPoller) toWorkflowTask(response *s.PollForDecisionTaskRes
910908
task := &workflowTask{
911909
task: response,
912910
historyIterator: historyIterator,
913-
autoConfigHint: response.GetAutoConfigHint(),
914911
}
915912
return task
916913
}
@@ -1119,9 +1116,7 @@ func (atp *activityTaskPoller) pollWithMetrics(ctx context.Context,
11191116
return nil, err
11201117
}
11211118
if response == nil || len(response.TaskToken) == 0 {
1122-
return &activityTask{
1123-
autoConfigHint: response.GetAutoConfigHint(),
1124-
}, nil
1119+
return &activityTask{task: response}, nil
11251120
}
11261121

11271122
workflowType := response.WorkflowType.GetName()
@@ -1133,7 +1128,7 @@ func (atp *activityTaskPoller) pollWithMetrics(ctx context.Context,
11331128
scheduledToStartLatency := time.Duration(response.GetStartedTimestamp() - response.GetScheduledTimestampOfThisAttempt())
11341129
metricsScope.Timer(metrics.ActivityScheduledToStartLatency).Record(scheduledToStartLatency)
11351130

1136-
return &activityTask{task: response, pollStartTime: startTime, autoConfigHint: response.GetAutoConfigHint()}, nil
1131+
return &activityTask{task: response, pollStartTime: startTime}, nil
11371132
}
11381133

11391134
// PollTask polls a new task

internal/internal_task_pollers_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,13 @@ func TestWorkflowTaskPoller(t *testing.T) {
8787
task,
8888
&workflowTask{
8989
task: task,
90-
autoConfigHint: task.AutoConfigHint,
9190
},
9291
},
9392
{
9493
"success with empty task",
9594
emptyTask,
9695
&workflowTask{
97-
task: nil,
98-
autoConfigHint: task.AutoConfigHint,
96+
task: emptyTask,
9997
},
10098
},
10199
} {
@@ -107,7 +105,6 @@ func TestWorkflowTaskPoller(t *testing.T) {
107105
resultTask, ok := result.(*workflowTask)
108106
assert.True(t, ok)
109107
assert.Equal(t, tt.expected.task, resultTask.task)
110-
assert.Equal(t, tt.expected.autoConfigHint, resultTask.autoConfigHint)
111108
})
112109
}
113110
})
@@ -139,15 +136,13 @@ func TestActivityTaskPoller(t *testing.T) {
139136
task,
140137
&activityTask{
141138
task: task,
142-
autoConfigHint: task.AutoConfigHint,
143139
},
144140
},
145141
{
146142
"success with empty task",
147143
emptyTask,
148144
&activityTask{
149-
task: nil,
150-
autoConfigHint: task.AutoConfigHint,
145+
task: emptyTask,
151146
},
152147
},
153148
} {
@@ -159,7 +154,6 @@ func TestActivityTaskPoller(t *testing.T) {
159154
resultTask, ok := result.(*activityTask)
160155
assert.True(t, ok)
161156
assert.Equal(t, tt.expected.task, resultTask.task)
162-
assert.Equal(t, tt.expected.autoConfigHint, resultTask.autoConfigHint)
163157
})
164158
}
165159
})

internal/internal_utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,11 @@ func getLengthOfStringPointer(s *string) int {
492492
}
493493
return len(*s)
494494
}
495+
496+
func isEmptyDecisionTask(r *s.PollForDecisionTaskResponse) bool {
497+
return r == nil || len(r.TaskToken) == 0
498+
}
499+
500+
func isEmptyActivityTask(r *s.PollForActivityTaskResponse) bool {
501+
return r == nil || len(r.TaskToken) == 0
502+
}

0 commit comments

Comments
 (0)