Sha256: d48060b8e917bd9b5c5a0ce8eef0c7cd19a3289b0590ba86cf0b12c02847ca93

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module WorkerExamples

  let(:env) { Asynchronic::Environment.new queue_engine, data_store }
  let(:queue_name) { :test_worker }
  let(:queue) { env.queue queue_name }

  def enqueue_processes
    processes = 5.times.map do
      env.build_process(WorkerJob, queue: :test_worker).tap(&:enqueue)
    end

    queue.must_enqueued processes
    processes.each { |p| p.must_be :queued? }

    processes
  end

  it 'Instance usage' do
    worker = Asynchronic::Worker.new :test_worker, env

    processes = enqueue_processes

    Thread.new do
      loop { break if queue.empty? }
      worker.stop 
    end

    worker.start

    processes.each { |p| p.must_be :completed? }
  end

  it 'Class usage' do
    Asynchronic.configure do |config|
      config.queue_engine = queue_engine
      config.data_store = data_store
    end

    processes = enqueue_processes

    Asynchronic::Worker.start :test_worker do |worker|
      loop { break if worker.queue.empty? }
      worker.stop 
    end
    
    processes.each { |p| p.must_be :completed? }   
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asynchronic-0.1.0 spec/worker/worker_examples.rb