R
R
rda19022015-09-27 16:50:23
Ruby on Rails
rda1902, 2015-09-27 16:50:23

Callback after executing a group of sidekiq tasks?

Good afternoon!
Periodically runs a rake task and runs sidekiq background tasks with different parameters.

Feed.find_each do |feed| #может быть 1000 элементов
    FeedUpdate.perform_async(feed.id)
  end

You need to somehow get a notification that these background tasks have been completed (it doesn’t matter if it was successful or not).
There are sidekiq batches, what I need, but it is paid ((
batch = Sidekiq::Batch.new
batch.description = "Batch description (this is optional)"
batch.on(:success, MyCallback)
batch.jobs do
  rows.each { |row| RowWorker.perform_async(row) }
end

posted your version
worker_ids = []
  Feed.find_each do |feed|
    worker_ids.push(FeedUpdate.perform_async(feed.id))
  end

  loop do
    sleep(0.5)
    in_progress = false
    worker_ids.each do |id|
      status = Sidekiq::Status::status(id)
      if (status == :queued) || (status == :working)
        in_progress = true
      end
    end
    break if in_progress == false
  end
Callback.run

My version works.
Are there any other variations or similar gems?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikiforov, 2015-09-27
@eoffsock

Look, there is such a microscope: https://github.com/socialpandas/sidekiq-superworker
You can hammer nails with them - paint a task queue, and at the end set a task that pulls the desired callback.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question