I want to query a rate-limited external API and save the information to the database. I want to get as close to the limit as possible so the information is up to date. My initial idea was to use sidekiq and create a job that was in a loop that checks for how many times the external API had been called in the past 1 second. This does not work well. I cant find any examples online. Most of the results were geared towards making an API in Ruby on Rails.
#config/initializers/data_poller.rb
require "redis"
redis = Redis.new
external_api = ExternalAPI::TestAPI1.new()
APIWorker.perform_async(external_api)
# app/workers/api_worker.rb
class APIWorker
include Sidekiq::Worker
def perform(external_api)
while true
if can_call_external_api
external_api.get_data
end
end
end
end