class Hoze::Worker

Attributes

source_factory[RW]

Public Class Methods

new() click to toggle source
# File lib/hoze/worker.rb, line 13
def initialize
  @source_config = Hoze::Configuration.new
  @source_factory = Hoze::SourceFactory.new
end

Public Instance Methods

go!() click to toggle source
# File lib/hoze/worker.rb, line 38
def go!
  @source = @source_factory.build(@source_config)
  @destination = @source_factory.build(@destination_config) if @destination_config
  @source.listen do |msg|
    begin
      msg.ack! if @source_config.auto_ack
      result = @process_fn.call msg
      @destination.push result, msg.metadata if @destination
    rescue Exception => e
      msg.retry!
      raise e
    end
  end
end
listen_to() { |source_config| ... } click to toggle source
# File lib/hoze/worker.rb, line 18
def listen_to &block
  yield @source_config
  puts "Source Configuration is: #{@source_config.inspect}"
  self
end
process() { |msg| ... } click to toggle source
# File lib/hoze/worker.rb, line 31
def process &block
  @process_fn = Proc.new do |msg|
    yield msg
  end
  self
end
push_to() { |destination_config| ... } click to toggle source
# File lib/hoze/worker.rb, line 24
def push_to &block
  @destination_config = Hoze::Configuration.new 'DEST'
  yield @destination_config
  puts "Destination Configuration is: #{@destination_config.inspect}"
  self
end