Class: Nerve::Reporter::Etcd

Inherits:
Base
  • Object
show all
Defined in:
lib/nerve/reporter/etcd.rb

Instance Method Summary collapse

Methods inherited from Base

#get_service_data

Methods included from Logging

configure_logger_for, #log, logger_for

Methods included from Utils

#responsive_sleep, #safe_run

Constructor Details

#initialize(service) ⇒ Etcd

Returns a new instance of Etcd.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/nerve/reporter/etcd.rb', line 6

def initialize(service)
  raise ArgumentError, "missing required argument etcd_host for new service watcher" unless service['etcd_host']
  @host = service['etcd_host']
  @port = service['etcd_port'] || 4003
  path = service['etcd_path'] || '/'
  @path = path.split('/').push(service['instance_id']).join('/')
  @data = parse_data(get_service_data(service))
  @key = nil
  @ttl = (service['check_interval'] || 0.5) * 5
  @ttl = @ttl.ceil
end

Instance Method Details

#ping?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nerve/reporter/etcd.rb', line 37

def ping?
  # we get a ping every check_interval.
  if @key
    # we have made a key: save it to prevent the TTL from expiring.
    etcd_save
  else
    # we haven't created a key, so just frob the etcd API to assure that
    # it's alive.
    @etcd.leader
  end
end

#report_downObject



33
34
35
# File 'lib/nerve/reporter/etcd.rb', line 33

def report_down
  etcd_delete
end

#report_upObject



29
30
31
# File 'lib/nerve/reporter/etcd.rb', line 29

def report_up()
  etcd_save
end

#startObject



18
19
20
21
22
# File 'lib/nerve/reporter/etcd.rb', line 18

def start()
  log.info "nerve: connecting to etcd at #{@host}:#{@port}"
  @etcd = ::Etcd.client(:host => @host, :port => @port)
  log.info "nerve: successfully created etcd connection to #{@host}:#{@port}"
end

#stopObject



24
25
26
27
# File 'lib/nerve/reporter/etcd.rb', line 24

def stop()
   report_down
   @etcd = nil
end