Class: Noah::Agents::Base
- Inherits:
-
Object
- Object
- Noah::Agents::Base
show all
- Defined in:
- lib/noah/agents/base_agent.rb
Constant Summary
collapse
- PREFIX =
"base://"
- NAME =
"base-agent"
- DEFAULT_CONCURRENCY =
1
- NEEDS_TRANSFORM =
false
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.inherited(base) ⇒ Object
9
10
11
12
|
# File 'lib/noah/agents/base_agent.rb', line 9
def self.inherited(base)
Noah::Watchers.register_agent(base)
base.send :include, EM::Deferrable
end
|
Instance Method Details
#logger ⇒ Object
33
34
35
36
|
# File 'lib/noah/agents/base_agent.rb', line 33
def logger
Noah::Log.logger.progname = self.class.to_s
Noah::Log.logger
end
|
#notify(event, message, watch_list) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/noah/agents/base_agent.rb', line 14
def notify(event, message, watch_list)
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
logger.info("Dispatched message to #{worklist.size} #{self.class.to_s} endpoints")
else
logger.info("No work to do")
end
rescue Exception => e
logger.fatal("Exectution of notify failed with #{e.message}")
end
|