Hi,
I am using sidekiq to make calls to a hotel booking api which has throttle limits.
So I use gem 'sidekiq-limit_fetch' in order to set a hard limit in order to not reach the maximum size of allowed requests.
At the same time I am restricted to post an amount of 1000 ids at the same time.
Now I need to receive quotes for e.g. 12000 ids.
So I slice into packages of 1000 like this:
job = QuoteJob.new
$redis.set(job.jid,{:status=>:started})
request = Api.new({
:arrival => Date.today + 30.days,
:departure => Date.today + 36.days,
:ids => sids
},job)
request.ids.each_slice(MAX_RESULTS).to_a.each do |_ids|
#done in sidekiq
kind_job = search_by_property_numbers(_options.merge({:PropertyNumbers => {:int => _ids}}), request)
job.dependent_jobs.push(kind_job)
end
The ultimate goal is to get informed when all the jobs have finished.
That's why I create am simple JobObject which knows about all the dependent jobs (kind_job) and there I do call another worker which asks for the sidekiq status
#Job object has a sidekiq worker
def perform(dependent_jobs,jid)
while !dependent_jobs.empty?
dependent_jobs.each do |jid|
if Sidekiq::Status::complete? jid or Sidekiq::Status::failed? jid or Sidekiq::Status::status(jid).nil?
dependent_jobs.delete(jid)
end
end
end
$redis.set(jid, {:status => :completed}) if dependent_jobs.empty?
end
My initial request created the Job object and triggers all the dependent workers with the api calls. At the same time the Job returns a jid which holds the status.
So I can poll the status e.g. with an ajax request.
I started writing tests I by doing this in development.rb
require 'sidekiq/testing/inline'
The problem is that the Sidekig::Status(jid) in perform is allways return :queued.
This confuses me since the doc says : An inline mode that runs the job immediately instead of enqueuing it
So first of all I d be very happy to head your thoughts on the general approach. And last but not least how do I know when the job finishes?
Help and feedback is highly appreciated.
Best regards,
Philip