Skip to content

Commit

Permalink
use pagination to get number of open workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
prajithp13 committed Aug 9, 2023
1 parent 020c659 commit b2394b6
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions pkg/scalers/temporal_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,37 @@ func (s *temporalWorkflowScaler) GetMetricsAndActivity(ctx context.Context, metr

// getQueueSize returns the queue size of open workflows.
func (s *temporalWorkflowScaler) getQueueSize(ctx context.Context) (int64, error) {
listOpenWorkflowExecutionsRequest := &workflowservice.ListOpenWorkflowExecutionsRequest{
Namespace: s.metadata.namespace,
Filters: &workflowservice.ListOpenWorkflowExecutionsRequest_TypeFilter{
TypeFilter: &tclfilter.WorkflowTypeFilter{
Name: s.metadata.workflowName,

var executionIds = make([]string, 0)
var nextPageToken []byte

for {
listOpenWorkflowExecutionsRequest := &workflowservice.ListOpenWorkflowExecutionsRequest{
Namespace: s.metadata.namespace,
MaximumPageSize: 1000,
NextPageToken: nextPageToken,
Filters: &workflowservice.ListOpenWorkflowExecutionsRequest_TypeFilter{
TypeFilter: &tclfilter.WorkflowTypeFilter{
Name: s.metadata.workflowName,
},
},
},
}
ws, err := s.tcl.ListOpenWorkflow(ctx, listOpenWorkflowExecutionsRequest)
if err != nil {
return 0, fmt.Errorf("failed to get workflows: %w", err)
}
ws, err := s.tcl.ListOpenWorkflow(ctx, listOpenWorkflowExecutionsRequest)
if err != nil {
return 0, fmt.Errorf("failed to get workflows: %w", err)
}

for _, execution := range ws.Executions {
executionId := execution.Execution.WorkflowId + "__" + execution.Execution.RunId
executionIds = append(executionIds, executionId)
}

if nextPageToken = ws.NextPageToken; len(nextPageToken) == 0 {
break
}
}

queueLength := int64(len(ws.Executions))
queueLength := int64(len(executionIds))
return queueLength, nil
}

Expand Down

0 comments on commit b2394b6

Please sign in to comment.