Class: ConsulStockpile::WatchEvent
- Defined in:
- lib/consul_stockpile/watch_event.rb
Constant Summary collapse
- EVENT =
'kv_update'.freeze
- URL =
'http://127.0.0.1:8500/v1/event/list'.freeze
- KEY =
'event/kv_update'.freeze
- LOCK_KEY =
'event/kv_update/lock'.freeze
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(handler:) ⇒ WatchEvent
constructor
A new instance of WatchEvent.
Methods inherited from Base
Constructor Details
#initialize(handler:) ⇒ WatchEvent
Returns a new instance of WatchEvent.
17 18 19 |
# File 'lib/consul_stockpile/watch_event.rb', line 17 def initialize(handler:) self.handler = handler end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
15 16 17 |
# File 'lib/consul_stockpile/watch_event.rb', line 15 def handler @handler end |
Instance Method Details
#call ⇒ Object
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 48 49 50 51 52 |
# File 'lib/consul_stockpile/watch_event.rb', line 21 def call Logger.tagged('WatchEvent') do Logger.info "Watching for event: #{EVENT}" response = Excon.get( URL, query: {name: EVENT}, expects: [200], connect_timeout: 5, read_timeout: 5, write_timeout: 5, tcp_nodelay: true ) handle_events(response.body) loop do index = response.headers['X-Consul-Index'] response = Excon.get( URL, query: {name: EVENT, index: index}, expects: [200], connect_timeout: 5, read_timeout: 86400, write_timeout: 5, tcp_nodelay: true ) handle_events(response.body) end end end |