@@ -26,7 +26,6 @@ package build_ids
2626
2727import (
2828 "context"
29- "math"
3029 "time"
3130
3231 enumspb "go.temporal.io/api/enums/v1"
6766
6867type (
6968 BuildIdScavangerInput struct {
70- VisibilityRPS float64
7169 NamespaceListPageSize int
7270 TaskQueueListPageSize int
7371 }
8684 // 2. workflows with that identifier that have yet to be indexed in visibility
8785 // The scavenger should allow enough time to pass before cleaning these build ids.
8886 removableBuildIdDurationSinceDefault dynamicconfig.DurationPropertyFn
87+ buildIdScavengerVisibilityRPS dynamicconfig.FloatPropertyFn
8988 }
9089
9190 heartbeatDetails struct {
@@ -105,6 +104,7 @@ func NewActivities(
105104 matchingClient matchingservice.MatchingServiceClient ,
106105 currentClusterName string ,
107106 removableBuildIdDurationSinceDefault dynamicconfig.DurationPropertyFn ,
107+ buildIdScavengerVisibilityRPS dynamicconfig.FloatPropertyFn ,
108108) * Activities {
109109 return & Activities {
110110 logger : logger ,
@@ -115,6 +115,7 @@ func NewActivities(
115115 matchingClient : matchingClient ,
116116 currentClusterName : currentClusterName ,
117117 removableBuildIdDurationSinceDefault : removableBuildIdDurationSinceDefault ,
118+ buildIdScavengerVisibilityRPS : buildIdScavengerVisibilityRPS ,
118119 }
119120}
120121
@@ -136,9 +137,6 @@ func (a *Activities) setDefaults(input *BuildIdScavangerInput) {
136137 if input .TaskQueueListPageSize == 0 {
137138 input .TaskQueueListPageSize = 100
138139 }
139- if input .VisibilityRPS == 0 {
140- input .VisibilityRPS = 1
141- }
142140}
143141
144142func (a * Activities ) recordHeartbeat (ctx context.Context , heartbeat heartbeatDetails ) {
@@ -155,7 +153,7 @@ func (a *Activities) ScavengeBuildIds(ctx context.Context, input BuildIdScavange
155153 return temporal .NewNonRetryableApplicationError ("failed to load previous heartbeat details" , "TypeError" , err )
156154 }
157155 }
158- rateLimiter := quotas .NewRateLimiter ( input . VisibilityRPS , int ( math . Ceil ( input . VisibilityRPS ) ))
156+ rateLimiter := quotas .NewDefaultOutgoingRateLimiter ( quotas . RateFn ( a . buildIdScavengerVisibilityRPS ))
159157 for {
160158 nsResponse , err := a .metadataManager .ListNamespaces (ctx , & persistence.ListNamespacesRequest {
161159 PageSize : input .NamespaceListPageSize ,
@@ -208,14 +206,16 @@ func (a *Activities) processNamespaceEntry(
208206 return err
209207 }
210208 for heartbeat .TaskQueueIdx < len (tqResponse .Entries ) {
209+ if ctx .Err () != nil {
210+ return ctx .Err ()
211+ }
211212 entry := tqResponse .Entries [heartbeat .TaskQueueIdx ]
212213 if err := a .processUserDataEntry (ctx , rateLimiter , * heartbeat , ns , entry ); err != nil {
213214 // Intentionally don't fail the activity on single entry.
214215 a .logger .Error ("Failed to update task queue user data" ,
215216 tag .WorkflowNamespace (ns .Name ().String ()),
216217 tag .WorkflowTaskQueueName (entry .TaskQueue ),
217218 tag .Error (err ))
218- continue
219219 }
220220 heartbeat .TaskQueueIdx ++
221221 a .recordHeartbeat (ctx , * heartbeat )
0 commit comments