Skip to content

feat: add exponential backoff for rate limit handling - #9

Merged
surrealwolf merged 2 commits into
mainfrom
backoff
Oct 21, 2025
Merged

surrealwolf merged 2 commits into
mainfrom
backoff

Conversation

@surrealwolf

Copy link
Copy Markdown
Collaborator

Overview

Implements exponential backoff retry logic to handle HTTP 429 (Too Many Requests) errors from the Hell Divers 2 API.

Problem

The data collector was hitting rate limit errors (429) on dispatches and other endpoints during collection cycles. The original 2-second delay between requests wasn't sufficient for the 5 requests/10 seconds API limit.

Solution

  • Added _fetch_with_backoff() method with exponential backoff on 429 errors
  • Backoff schedule: 2s → 4s → 8s → 16s → 32s (up to 5 retries)
  • Updated all 10 scraper methods to use automatic retry logic
  • Gracefully handles rate limit errors with transparent logging
  • Maintains type safety with isinstance() checks for dict/list returns

Changes

  • src/scraper.py: Refactored all HTTP requests to use centralized backoff handler
  • Simplified method implementations (removed duplicate try/except blocks)
  • Added warning logs with retry attempt information

Testing

  • ✅ 11/11 tests passing
  • ✅ Ruff linting: All checks passed
  • ✅ Mypy type checking: 0 issues found

Related Issues

Fixes issue where collection cycle fails with "429 Client Error: Too Many Requests"

Copilot AI review requested due to automatic review settings October 21, 2025 05:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements exponential backoff retry logic to handle HTTP 429 (Too Many Requests) errors from the Hell Divers 2 API, addressing rate limit violations during data collection cycles.

Key Changes:

  • Introduced centralized _fetch_with_backoff() method with exponential backoff (2s → 4s → 8s → 16s → 32s over 5 retries)
  • Refactored all 10 scraper methods to use the new backoff handler
  • Added type safety checks with isinstance() for list-returning endpoints

Comment thread src/scraper.py
Comment thread src/scraper.py Outdated
Comment thread src/scraper.py Outdated
Comment thread src/scraper.py Outdated
@surrealwolf
surrealwolf merged commit efcaa2a into main Oct 21, 2025
8 checks passed
@surrealwolf
surrealwolf deleted the backoff branch October 21, 2025 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants