Class: Matron::Client

Inherits:
Object
  • Object
show all
Includes:
Matron::Consul::Recursable
Defined in:
lib/matron/client.rb

Defined Under Namespace

Classes: NameRequired

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Client

Returns a new instance of Client.

Raises:



13
14
15
16
17
# File 'lib/matron/client.rb', line 13

def initialize( name )
  @name = name
  @name = @name.to_s if @name.kind_of? Symbol
  raise NameRequired unless @name.kind_of?(String) && @name.size > 0
end

Instance Method Details

#configurationObject



36
37
38
39
40
# File 'lib/matron/client.rb', line 36

def configuration
  fetch_recursively("matron/apps/#{@name}/properties/", false).map do |property|
    [property[:key].split('/').last.to_sym, property[:value]]
  end.to_h
end

#configure!(options) ⇒ Object



29
30
31
32
33
34
# File 'lib/matron/client.rb', line 29

def configure! options
  options = {:max_query_time => 600, :refresh_rate => 1}.merge options
  (options || {}).each do |k, v|
    ::Diplomat::Kv.put "matron/apps/#{@name}/properties/#{k}", v.to_s
  end
end

#hostsObject



42
43
44
# File 'lib/matron/client.rb', line 42

def hosts
  fetch_recursively "matron/apps/#{@name}/hosts/"
end

#register!Object



19
20
21
22
# File 'lib/matron/client.rb', line 19

def register!
  ::Diplomat::Kv.put "matron/apps/#{@name}/hosts/#{ip_address}", ip_address
  ::Diplomat::Kv.put "matron/hosts/#{ip_address}", @name
end

#unregister!(host = nil) ⇒ Object



24
25
26
27
# File 'lib/matron/client.rb', line 24

def unregister! host=nil
  ::Diplomat::Kv.delete "matron/apps/#{@name}/hosts/#{host || ip_address}"
  ::Diplomat::Kv.delete "matron/hosts/#{host || ip_address}"
end