Commit b0c97789 authored by John E. Vincent's avatar John E. Vincent

agent.rb

parent bfc8d7ff
module Noah::Agents
class Base
PREFIX = "base"
PREFIX = "base://"
NAME = "base-agent"
DEFAULT_CONCURRENCY = 1
NEEDS_TRANSFORM = false
def self.inherited(base)
Noah::Watchers.register_agent(base)
......@@ -11,12 +12,13 @@ module Noah::Agents
end
def notify(event, message, watch_list)
logger.info("#{self.class} worker initiated")
logger.info("#{self.class.to_s} worker initiated")
worklist = []
watch_list.select{|w| worklist << w[:endpoint] if (w[:endpoint] =~ /^#{self.class::PREFIX}/ && event =~ /^#{w[:pattern]}/) }
if worklist.size >= 1
logger.info("Dispatching message to #{worklist.size} #{self.class.to_s} endpoints")
EM::Iterator.new(worklist, self.class::DEFAULT_CONCURRENCY).each do |ep, iter|
ep, message = transform(ep, message) if self.class::NEEDS_TRANSFORM == true
work!(ep, message)
iter.next
end
......
......@@ -5,7 +5,7 @@ module Noah::Agents
PREFIX = "http://"
NAME = self.class.to_s
DEFAULT_CONCURRENCY = 500
DEFAULT_CONCURRENCY = 50
def work!(ep, message)
logger.info("Sending message to (#{ep})")
......
......@@ -12,6 +12,7 @@ module Noah
model.send :attribute, :tags
model.send :index, :tag
model.send :attribute, :metadata
# removing this as it's simply redundant
# model.after :save, :notify_via_redis_save
......
......@@ -9,12 +9,13 @@ module Noah
def validate
super
assert_present :name
assert_unique :name
end
def to_hash
arr = []
configurations.sort.each {|c| arr << c.to_hash}
super.merge(:name => name, :created_at => created_at, :updated_at => updated_at, :configurations => arr)
super.merge(:name => name, :configuration => arr, :created_at => created_at, :updated_at => updated_at)
end
class << self
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment