Sha256: f3a96e9077a778b4158bd27b984a4a3f5ca69e8df020fb6a0b0a32a2e05fd4ca

Contents?: true

Size: 774 Bytes

Versions: 30

Compression:

Stored size: 774 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.perform_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

30 entries across 30 versions & 1 rubygems

Version Path
services-1.2.0 spec/support/helpers.rb
services-1.1.1 spec/support/helpers.rb
services-1.1.0 spec/support/helpers.rb
services-1.0.0 spec/support/helpers.rb
services-0.4.0 spec/support/helpers.rb
services-0.3.4 spec/support/helpers.rb
services-0.2.14 spec/support/helpers.rb
services-0.2.13 spec/support/helpers.rb
services-0.2.12 spec/support/helpers.rb
services-0.2.11 spec/support/helpers.rb