Sha256: c54827705486e3effe03572c302ddb10e852a524e45f642a50a6ddf066db4e42

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module WorkerExamples

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

  after do
    data_store.clear
    queue_engine.clear
  end

  def enqueue_processes
    processes = 5.times.map do
      env.create_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

4 entries across 4 versions & 1 rubygems

Version Path
asynchronic-3.0.3 spec/worker/worker_examples.rb
asynchronic-3.0.2 spec/worker/worker_examples.rb
asynchronic-3.0.1 spec/worker/worker_examples.rb
asynchronic-3.0.0 spec/worker/worker_examples.rb