Sha256: 0f5be9ebd6ed4807ac49c70af34281521b726f3455af7502d0b1b1d5d6a14133

Contents?: true

Size: 831 Bytes

Versions: 20

Compression:

Stored size: 831 Bytes

Contents

class Asynchronic::Worker

  attr_reader :queue
  attr_reader :queue_name
  attr_reader :env
  attr_reader :listener

  def initialize(queue_name, env)
    @queue_name = queue_name
    @queue = env.queue_engine[queue_name]
    @env = env
    @listener = env.queue_engine.listener
  end

  def start
    Asynchronic.logger.info('Asynchronic') { "Starting worker of #{queue_name} (#{Process.pid})" }

    Signal.trap('QUIT') { stop }
    
    listener.listen(queue) do |pid|
      env.load_process(pid).execute
    end
  end

  def stop
    Asynchronic.logger.info('Asynchronic') { "Stopping worker of #{@queue_name} (#{Process.pid})" }
    listener.stop
  end

  def self.start(queue_name, &block)
    worker = new queue_name, Asynchronic.environment
    Thread.new { block.call(worker) } if block_given?
    worker.start
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
asynchronic-1.6.3 lib/asynchronic/worker.rb
asynchronic-1.6.2 lib/asynchronic/worker.rb
asynchronic-1.6.1 lib/asynchronic/worker.rb
asynchronic-1.6.0 lib/asynchronic/worker.rb
asynchronic-1.5.2 lib/asynchronic/worker.rb
asynchronic-1.5.1 lib/asynchronic/worker.rb
asynchronic-1.5.0 lib/asynchronic/worker.rb
asynchronic-1.4.0 lib/asynchronic/worker.rb
asynchronic-1.3.1 lib/asynchronic/worker.rb
asynchronic-1.3.0 lib/asynchronic/worker.rb
asynchronic-1.2.2 lib/asynchronic/worker.rb
asynchronic-1.2.1 lib/asynchronic/worker.rb
asynchronic-1.2.0 lib/asynchronic/worker.rb
asynchronic-1.1.1 lib/asynchronic/worker.rb
asynchronic-1.1.0 lib/asynchronic/worker.rb
asynchronic-1.0.0 lib/asynchronic/worker.rb
asynchronic-0.3.1 lib/asynchronic/worker.rb
asynchronic-0.3.0 lib/asynchronic/worker.rb
asynchronic-0.2.3 lib/asynchronic/worker.rb
asynchronic-0.2.2 lib/asynchronic/worker.rb