Skip to content

fix: back off exponentially when retrying rate-limited Discogs cover fetch - #498

Open
yottanami wants to merge 1 commit into
blackcandy-org:masterfrom
yottanami:agent/75-discogs-backoff
Open

fix: back off exponentially when retrying rate-limited Discogs cover fetch#498
yottanami wants to merge 1 commit into
blackcandy-org:masterfrom
yottanami:agent/75-discogs-backoff

Conversation

@yottanami

Copy link
Copy Markdown

What

Replaces the flat wait: 1.minute on AttachCoverImageFromDiscogsJob's rate-limit retry with Rails' built-in wait: :polynomially_longer backoff.

Why

As reported in #414: Discogs rate-limits to 60 authenticated requests/minute. With a large library, hundreds/thousands of jobs get queued after the first batch, and every one of them independently retries after exactly 60 seconds. That keeps the request rate pinned at the limit forever instead of letting it drain — attempts: :unlimited stays unlimited, but now the wait between retries grows with the number of attempts instead of staying flat.

How this was tested

I don't have a Ruby/Rails environment in my sandbox, so I could not run rails test:all or rails lint:all locally. This is a one-line change to a retry_on keyword argument — no new logic. The existing test (test/jobs/attach_cover_image_from_discogs_job_test.rb, "should retry the job when api request has been rate limited") already exercises the retry-on-rate-limit path and doesn't assert on the wait duration, so it should be unaffected by this change, but I'd appreciate CI/a maintainer confirming.

Closes #414


AI disclosure: This PR (diff, commit message, and this description) was authored by an AI coding agent (Claude). I found no CONTRIBUTING.md or AI-usage policy in this repo to check against.

…fetch

AttachCoverImageFromDiscogsJob retried Integrations::Service::TooManyRequests
with a flat 1-minute wait and unlimited attempts. Discogs rate-limits to 60
authenticated requests/minute, so for a library with many queued jobs (a
1600-album library queues ~1540 jobs after the first batch), every rate-limited
job retries again after exactly 60 seconds, keeping the request rate pinned at
the limit indefinitely instead of letting it drain.

Use Rails' built-in :polynomially_longer backoff instead of a flat wait, so
retry spacing grows with the number of attempts and the queue actually drains.

Closes blackcandy-org#414
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.

blackcandy spams discogs with requests on large media library

1 participant