WagnerMatosUK
WagnerMatosUK

Reputation: 4429

How can I use Sidekiq delay with a worker

I have a situation where I have a worker that makes multiple calls to an external API. The problem is that we have a threshold of many calls we can make to this API per hour.

What I'd like to do is to create a worker which will make these many sequential calls to this external API. If in between these calls we get an error because we've reached the number of connections we're allowed in that hour, the worker would then save the document and schedule a new worker to complete the remaining API calls at a later time (maybe 1, 2 hours later. Ideally this should be configurable e.g.: 10mins, 1hour, etc).

Is there someway I could achieve this?

Upvotes: 6

Views: 9446

Answers (2)

Mike Perham
Mike Perham

Reputation: 22208

You want Sidekiq Enterprise and its Rate Limiting API. The alternative is tracking the rate limit yourself and rescheduling the job manually.

https://github.com/mperham/sidekiq/wiki/Ent-Rate-Limiting

Upvotes: 2

Aschen
Aschen

Reputation: 1771

With SideKiq you can scheduled when a job will be executed with a friendly API :

MyWorker.perform_in(3.hours, 'mike', 1) # Expect a duration
MyWorker.perform_at(3.hours.from_now, 'mike', 1) # Expect a date

Check it out : Scheduled Jobs

Upvotes: 9

Related Questions