-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathcustom_agents.rb
48 lines (38 loc) · 1.11 KB
/
custom_agents.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'custom_agent_context'
# This class is responsible for hooking up custom agents into the system.
# Currently it dynamically creates backing Agent class to do the heavy lifting and
# provides a 'context' to proxy data between the two.
class CustomAgents
class Config
attr_accessor :description, :display_name, :default_options
end
def self.register(klass)
config = klass.register(Config.new)
class_name = "Agents::Proxy#{klass}"
display_name = config.display_name || klass
eval <<-DYNAMIC
class #{class_name} < ::Agent
description #{config.description.inspect}
default_schedule 'never'
display_name #{display_name.inspect}
def default_options
#{config.default_options.inspect}
end
def check
impl.check
end
def receive(message)
impl.receive(message)
end
private
def impl
@impl ||= begin
context = CustomAgentContext.new(self)
#{klass}.new(context)
end
end
end
DYNAMIC
::Agent::TYPES << class_name
end
end