class Asynchronic::Worker

Attributes

environment[R]
listener[R]
queue[R]
queue_name[R]

Public Class Methods

new(queue_name, environment) click to toggle source
# File lib/asynchronic/worker.rb, line 5
def initialize(queue_name, environment)
  @queue_name = queue_name
  @queue = environment.queue_engine[queue_name]
  @environment = environment
  @listener = environment.queue_engine.listener
end
start(queue_name, &block) click to toggle source
# File lib/asynchronic/worker.rb, line 27
def self.start(queue_name, &block)
  worker = new queue_name, Asynchronic.environment
  Thread.new { block.call(worker) } if block_given?
  worker.start
end

Public Instance Methods

start() click to toggle source
# File lib/asynchronic/worker.rb, line 12
def start
  Asynchronic.logger.info('Asynchronic') { "Starting worker of #{queue_name} (#{Process.pid})" }

  Signal.trap('QUIT') { stop }

  listener.listen(queue) do |pid|
    environment.load_process(pid).execute
  end
end
stop() click to toggle source
# File lib/asynchronic/worker.rb, line 22
def stop
  Asynchronic.logger.info('Asynchronic') { "Stopping worker of #{queue_name} (#{Process.pid})" }
  listener.stop
end