Class: HotPotato::Worker

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

Overview

Workers manipulate data from other workers or faucets. Examples include: Calculate Scores, Merge Data, and Filter Data. Each worker is a ruby file in the app directory that extends HotPotato::Worker and implements the perform(message) method. For each message the worker wants to send to the next AppTask, the send_message method should be called.

class Influencer < HotPotato::Worker

  def perform(message)
    message["influence"] = rand(100)
    send_message message
  end

end

Direct Known Subclasses

__NAME__

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



33
34
35
36
# File 'lib/hot_potato/worker.rb', line 33

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

#start(queue_in) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hot_potato/worker.rb', line 20

def start(queue_in)
  @queue_out = underscore(self.class.name.to_sym)
  if !self.respond_to?('perform')
    log.error "The Worker #{self.class.name} does not implement a perform method."
    exit 1
  end
  start_heartbeat_service      
  queue_subscribe(queue_in) do |m|
    count_message_in
    perform m
  end
end