Class: ConsulStockpile::WatchEvent

Inherits:
Object
  • Object
show all
Includes:
Metaractor
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 Method Summary collapse

Instance Method Details

#callObject



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
48
49
50
# File 'lib/consul_stockpile/watch_event.rb', line 19

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