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

agent.rb

parent bfc8d7ff
module Noah::Agents module Noah::Agents
class Base class Base
PREFIX = "base" PREFIX = "base://"
NAME = "base-agent" NAME = "base-agent"
DEFAULT_CONCURRENCY = 1 DEFAULT_CONCURRENCY = 1
NEEDS_TRANSFORM = false
def self.inherited(base) def self.inherited(base)
Noah::Watchers.register_agent(base) Noah::Watchers.register_agent(base)
...@@ -11,12 +12,13 @@ module Noah::Agents ...@@ -11,12 +12,13 @@ module Noah::Agents
end end
def notify(event, message, watch_list) def notify(event, message, watch_list)
logger.info("#{self.class} worker initiated") logger.info("#{self.class.to_s} worker initiated")
worklist = [] worklist = []
watch_list.select{|w| worklist << w[:endpoint] if (w[:endpoint] =~ /^#{self.class::PREFIX}/ && event =~ /^#{w[:pattern]}/) } watch_list.select{|w| worklist << w[:endpoint] if (w[:endpoint] =~ /^#{self.class::PREFIX}/ && event =~ /^#{w[:pattern]}/) }
if worklist.size >= 1 if worklist.size >= 1
logger.info("Dispatching message to #{worklist.size} #{self.class.to_s} endpoints") logger.info("Dispatching message to #{worklist.size} #{self.class.to_s} endpoints")
EM::Iterator.new(worklist, self.class::DEFAULT_CONCURRENCY).each do |ep, iter| 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) work!(ep, message)
iter.next iter.next
end end
......
...@@ -5,7 +5,7 @@ module Noah::Agents ...@@ -5,7 +5,7 @@ module Noah::Agents
PREFIX = "http://" PREFIX = "http://"
NAME = self.class.to_s NAME = self.class.to_s
DEFAULT_CONCURRENCY = 500 DEFAULT_CONCURRENCY = 50
def work!(ep, message) def work!(ep, message)
logger.info("Sending message to (#{ep})") logger.info("Sending message to (#{ep})")
......
...@@ -12,6 +12,7 @@ module Noah ...@@ -12,6 +12,7 @@ module Noah
model.send :attribute, :tags model.send :attribute, :tags
model.send :index, :tag model.send :index, :tag
model.send :attribute, :metadata
# removing this as it's simply redundant # removing this as it's simply redundant
# model.after :save, :notify_via_redis_save # model.after :save, :notify_via_redis_save
......
...@@ -9,12 +9,13 @@ module Noah ...@@ -9,12 +9,13 @@ module Noah
def validate def validate
super super
assert_present :name assert_present :name
assert_unique :name
end end
def to_hash def to_hash
arr = [] arr = []
configurations.sort.each {|c| arr << c.to_hash} 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 end
class << self 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