Skip to content

Commit a7f4d6b

Browse files
committed
fix: better recovery strateg
1 parent de0bacd commit a7f4d6b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/fipe/client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ export class FipeClient {
5050

5151
private recordSuccess(): void {
5252
this.successCount++;
53-
if (this.successCount >= 10 && this.currentThrottleMs > env.RATE_LIMIT_MS) {
54-
const newThrottle = Math.max(this.currentThrottleMs - 50, env.RATE_LIMIT_MS);
53+
// After 5 consecutive successes, halve the distance to baseline
54+
if (this.successCount >= 5 && this.currentThrottleMs > env.RATE_LIMIT_MS) {
55+
const newThrottle = Math.max(
56+
Math.floor((this.currentThrottleMs + env.RATE_LIMIT_MS) / 2),
57+
env.RATE_LIMIT_MS,
58+
);
5559
if (newThrottle !== this.currentThrottleMs) {
5660
console.log(
5761
`Throttle recovery: decreasing from ${this.currentThrottleMs}ms to ${newThrottle}ms`,

0 commit comments

Comments
 (0)