Class: Serfx::Utils::Handler::SerfEvent
- Inherits:
-
Object
- Object
- Serfx::Utils::Handler::SerfEvent
- Defined in:
- lib/serfx/utils/handler.rb
Overview
when serf agent invokes a handler it passes the event payload through STDIN. while event metadata such as event type, name etc is passed as a set of environment variables.
- SerfEvent
-
encapsulates such event.
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(env = ENV, stdin = STDIN) ⇒ SerfEvent
constructor
A new instance of SerfEvent.
Constructor Details
#initialize(env = ENV, stdin = STDIN) ⇒ SerfEvent
Returns a new instance of SerfEvent.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/serfx/utils/handler.rb', line 33 def initialize(env = ENV, stdin = STDIN) @environment = {} @payload = nil @name = nil env.keys.select { |k| k =~ /^SERF/ }.each do | k| @environment[k] = env[k].strip end @type = @environment['SERF_EVENT'] case @type when 'query' @name = @environment['SERF_QUERY_NAME'] begin @payload = stdin.read_nonblock(4096).strip rescue Errno::EAGAIN, EOFError end when 'user' @name = @environment['SERF_USER_EVENT'] begin @payload = stdin.read_nonblock(4096).strip rescue Errno::EAGAIN, EOFError end end end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
29 30 31 |
# File 'lib/serfx/utils/handler.rb', line 29 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/serfx/utils/handler.rb', line 29 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
29 30 31 |
# File 'lib/serfx/utils/handler.rb', line 29 def payload @payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
29 30 31 |
# File 'lib/serfx/utils/handler.rb', line 29 def type @type end |