Sha256: c8834af5a7f64103527187dae1971b6f2b64b67c105c75f79d76a7b541bf7f4a

Contents?: true

Size: 682 Bytes

Versions: 4

Compression:

Stored size: 682 Bytes

Contents

require 'sidekiq/api'

ExpectedDataNotFoundError = Class.new(StandardError)

def wait_for(&block)
  10.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_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

4 entries across 4 versions & 1 rubygems

Version Path
services-0.2.9 spec/support/helpers.rb
services-0.2.8 spec/support/helpers.rb
services-0.2.7 spec/support/helpers.rb
services-0.2.6 spec/support/helpers.rb