ruby on rails - Dependent jobs in Sidekiq - How to avoid the one that launches to finish? -
i have following job structure in rails app:
def perform(page_ids, email, order_id) job_ids = [] page_ids.each |id| job_ids << shoebuilder.perform_async(id, order_id) end checkstatus.perform_async(job_ids, email) unless job_ids.empty? end
basically launch n shoebuilders, , have checkstatus worker keeps checking if of jobs have finished in order send email user. here how checkstatus looks:
def perform(ids, email, order_id) finished = [] while finished.size < ids.size ids.each |id| status = sidekiq::status::status(id) # consider finished if has been completed or failed if (( sidekiq::status::complete?(id) || sidekiq::status::failed?(id) ) && !finished.include?(id)) finished << id end end sleep 5 end notifier.thanks(email, order_id).deliver end
so, problem here following:
the shoebuilder work, @ point, if has not been able find information (it parser worker), launch instance of shoebuilder. , here comes problem:
- when launch shoebuilder job within shoebuilder job, first 1 finishes. how can avoid that?
- if can't avoid that, how can tell checkstatus, take account new job id, instead of original one?
if you're not able use sidekiq pro, sidekiq superworker supports this:
# config/initializers/superworkers.rb superworker.create(:mysuperworker, :page_ids, :email, :order_id) batch page_ids: :page_id shoebuilder :page_id, :order_id end notifier :email, :order_id end # anywhere mysuperworker.perform_async([1, 2, 3], 'foo@gmail.com', 378)
when run mysuperworker, queue shoebuilder jobs of page ids. when of have finished, notifier run. (disclaimer: i'm gem's author.)
Comments
Post a Comment