Sha256: 7e2e002b3ffc083df7b3374a29ca470566032d606eb0d130340734e568f76b0e

Contents?: true

Size: 828 Bytes

Versions: 1

Compression:

Stored size: 828 Bytes

Contents

require 'singleton'
require 'rocketman/job_queue'

module Rocketman
  class Pool
    include Singleton

    attr_reader :jobs

    def initialize
      worker_count = Rocketman.configuration.worker_count
      latency = Rocketman.configuration.latency

      @latency = latency
      @jobs = Rocketman::JobQueue.new
      @workers = []

      worker_count.times do
        @workers << spawn_worker
      end

      # spawn_supervisor # TODO: Write a supervisor to monitor workers health, and restart if necessary
    end

    private

    def spawn_worker
      Thread.abort_on_exception = true if Rocketman.configuration.debug

      Thread.new do
        loop do
          job = @jobs.pop
          job.notify_consumers # Job is an instance of Rocketman::Event
          sleep @latency
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rocketman-0.2.0 lib/rocketman/pool.rb