Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call function when a sidekiq-superworker's superjob is completed

I have a setup of two Sidekiq workers in my Rails 4.2 app where the first one performs several jobs and the other one sends en email when all those jobs have been completed. These two are coupled in this superworker:

Superworker.define(:PrioritySuperworker, :object_class, :object_id, :priority_ids) do
  batch priority_ids: :priority_id  do
    PriorityMailsWorker :object_class, :object_id, :priority_id
  end
  SendConfirmationWorker :object_class, :object_id
end

I would like to perform another operation in the model where this superworker is called, but only if the superjob has been completed (which means all the subjobs in it were also completed). I've seen that Sidekiq Pro can fire a callback on completion of a batch but I can't afford using it since I work on an open source platform. Is there any way this could be done using Superworker or any other free tool?

like image 912
Georgiana.b Avatar asked Oct 31 '22 00:10

Georgiana.b


1 Answers

I do not know if it is an option, but if I am not mistaken, it looks pretty much as what you need.

According to sidekiq-sperworker gem docs, you could just set up the third worker and add it to superworker, thus making sure it only runs when all previous are completed.

With your example it'll look as follows:

Superworker.define(:PrioritySuperworker, :object_class, :object_id, :priority_ids) do
  batch priority_ids: :priority_id  do
    PriorityMailsWorker          :object_class, :object_id, :priority_id
  end
  SendConfirmationWorker         :object_class, :object_id
  PerformAnotherOperationInModel :object_class, :object_id
end
like image 174
Andrey Deineko Avatar answered Nov 09 '22 04:11

Andrey Deineko