Sha256: 4a7208e31d03761ffeb98aa8fa2e9bca47888374c05dfd925f9b4a3953aaf674
Contents?: true
Size: 771 Bytes
Versions: 2
Compression:
Stored size: 771 Bytes
Contents
require 'sidekiq/api' ExpectedDataNotFoundError = Class.new(StandardError) def wait_for(&block) 50.tries on: ExpectedDataNotFoundError, delay: 0.1 do block.call or raise ExpectedDataNotFoundError end end def worker_with_jid(jid) Sidekiq::Workers.new.detect do |_, _, work| work['payload']['jid'] == jid end end def wait_for_all_jobs_to_finish wait_for do Sidekiq::Workers.new.size == 0 end end def wait_for_job_to_run(job_class, *args, &block) job_class.call_async(*args).tap do |jid| wait_for { worker_with_jid(jid) } block.call if block_given? end end def wait_for_job_to_run_and_finish(job_class, *args, &block) wait_for_job_to_run(job_class, *args, &block).tap do |jid| wait_for { worker_with_jid(jid).nil? } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
services-5.1.0 | spec/support/helpers.rb |
services-5.0.0 | spec/support/helpers.rb |