Skip to content

feat: Flickr rate limit retry with backoff#84

Merged
DaxServer merged 2 commits intomainfrom
feat/flickr-rate-limit-retry
Apr 10, 2026
Merged

feat: Flickr rate limit retry with backoff#84
DaxServer merged 2 commits intomainfrom
feat/flickr-rate-limit-retry

Conversation

@DaxServer
Copy link
Copy Markdown
Owner

When the Flickr API returns HTTP 429, get_flickr_photo now retries with delays of 1, 3, and 5 minutes before giving up. On exhaustion it raises RateLimitExhausted which stops the run loop cleanly (same pattern as DryRunStop).

Also sets up pytest and adds a Tests GitHub Actions workflow, and fixes the ty check command to target src/ only.

DaxServer and others added 2 commits April 10, 2026 19:30
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ci: add tests workflow and update ty check command in CLAUDE.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a retry mechanism for handling HTTP 429 (Too Many Requests) errors in the FlickrBot using a backoff strategy. It also introduces the RateLimitExhausted exception, refactors DryRunStop to be public, updates project dependencies to include pytest, and adds comprehensive unit tests for the new rate-limiting logic. The review feedback suggests improving the retry logic by checking for the Retry-After header and expanding retry coverage to include other transient errors like connection timeouts or 500-series server responses.

Comment on lines +156 to +165
except httpx.HTTPStatusError as e:
if e.response.status_code != 429:
logger.error(f"[{flickr_photo_id}] {e}")
return
delay = next(delays, None)
if delay is None:
logger.critical(f"[{flickr_photo_id}] Rate limit exhausted after all retries")
raise RateLimitExhausted
logger.warning(f"[{flickr_photo_id}] Rate limited, retrying in {delay}s")
time.sleep(delay)
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.

medium

The retry logic for HTTP 429 (Too Many Requests) uses hardcoded delays. While this is a good start, the Flickr API typically returns a Retry-After header indicating how long the client should wait. It would be more efficient to respect this header if present, falling back to the hardcoded delays only if the header is missing.

Comment on lines +166 to +168
except Exception as e:
logger.error(f"[{flickr_photo_id}] {e}")
return
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.

medium

This catch-all Exception block silently skips the photo on any error that isn't a 429, 404, or 403. While logging the error is good, consider if certain other exceptions (like connection timeouts or 5xx server errors) should also trigger a retry with backoff, as they are often transient.

@DaxServer DaxServer merged commit 2030ecb into main Apr 10, 2026
5 checks passed
@DaxServer DaxServer deleted the feat/flickr-rate-limit-retry branch April 10, 2026 17:37
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.

1 participant