Reputation: 2378
I'm using sidekiq-superworkers and sidekiq under a project I'm currently working. I have set Sidekiq::Testing.inline! under spec_helper for my integration tests, is there anything similar on superworkers? I need to run workers and wait for they to finish in order to perform some asserts, how can this be achieved?
Upvotes: 1
Views: 436
Reputation: 343
As far as I know, Superworker does not have any way to specify conditions inside it's create
block.
I had a similar problem where I had to wait for a set of jobs to complete before performing some actions and I went ahead with using sidekiq_status.
The basic idea is that you collect all the job ids of the jobs you launch and then poll if any of the job is still processing before performing the next action.
Eg:
job_pool = []
(1..100).each do
# Collect all the job ids that you have launched.
job_pool.push SomeWorker.perform_async
end
jobs_are_working = true
while jobs_are_working
# Wait as long as at least one job is working or waiting
waiting_job = job_pool.detect do |job_id|
job_status = SidekiqStatus::Container.load(job_id).status
job_status == "waiting" || job_status == "working"
end
end
It might be a good idea to wrap the whole waiting part inside a Timeout block so that you don't get stuck indefinitely.
Upvotes: 1