Skip to content

Commit 75b9426

Browse files
committed
Add dynamic rate limit handling in ThrottleMiddleware to pause on low limits
1 parent 4995358 commit 75b9426

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

api/ruby/find-inactive-members/find_inactive_members.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ def calculate_dynamic_delay
6666
def throttle_request
6767
current_time = Time.now
6868

69+
# Check if rate limit is critically low and pause until reset if needed
70+
if @github_rate_limit_remaining && @github_rate_limit_remaining < 50 && @github_rate_limit_reset
71+
time_until_reset = [@github_rate_limit_reset - current_time.to_i, 0].max
72+
if time_until_reset > 0
73+
pause_time = time_until_reset + 5 # Add 5 second buffer
74+
minutes = (pause_time / 60.0).round(1)
75+
$stderr.print "\n⚠️ RATE LIMIT LOW: Only #{@github_rate_limit_remaining} requests remaining!\n"
76+
$stderr.print "⏸️ Pausing for #{minutes} minutes until rate limit resets (#{pause_time} seconds total)\n"
77+
$stderr.print "⏰ Will resume at approximately #{(Time.now + pause_time).strftime('%H:%M:%S')}\n\n"
78+
sleep(pause_time)
79+
80+
# Reset our tracking after the pause
81+
@github_rate_limit_remaining = nil # Will be updated on next response
82+
@github_rate_limit_reset = nil
83+
end
84+
end
85+
6986
# Reset counter if we've moved to a new hour (sliding window)
7087
if current_time - @hour_start_time >= 3600
7188
@request_count = 0

0 commit comments

Comments
 (0)