Class: HotPotato::Faucet

Inherits:
Object
  • Object
show all
Includes:
AppTask
Defined in:
lib/hot_potato/faucet.rb

Overview

Faucets inject data into the system. Examples include: Twitter Reader, SMTP, and Tail Log File. Each faucet is a ruby file in the app directory that extends HotPotato::Faucet and implements the perform method. For each message received, the method should call the send_message to send it to the next AppTask.

class TwitterFaucet < HotPotato::Faucet

  def perform
    TweetStream::Client.new("user", "secret").sample do |s|
      message = {}
      message["username"] = s.user.screen_name
      message["text"]     = s.text
      send_message message
    end
  end

end

Constant Summary

Constants included from AppTask

AppTask::HEARTBEAT_EXPIRE, AppTask::HEARTBEAT_INTERVAL, AppTask::MESSAGE_COUNT_EXPIRE

Constants included from Core

Core::CONFIG_PATH

Instance Method Summary collapse

Methods included from AppTask

#count_message_in, #count_message_out, #start_heartbeat_service

Methods included from Core

#acquire_lock, #config, #log, #queue_inject, #queue_subscribe, #release_lock, #set_logger, #stat

Instance Method Details

#send_message(m) ⇒ Object



34
35
36
37
# File 'lib/hot_potato/faucet.rb', line 34

def send_message(m)
  queue_inject @queue_out, m
  count_message_out
end

#startObject



24
25
26
27
28
29
30
31
32
# File 'lib/hot_potato/faucet.rb', line 24

def start
  @queue_out = underscore(self.class.name.to_sym)
  if self.respond_to?('perform')
    start_heartbeat_service
    perform
  else
    log.error "The Faucet #{self.class.name} does not implement a perform method."
  end      
end