Class: Odania::Service

Inherits:
Consul
  • Object
show all
Defined in:
lib/odania/service.rb

Instance Method Summary collapse

Instance Method Details

#consul_service_config(plugin_name, plugin_instance_name, ip, tags = [], port = 80) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/odania/service.rb', line 11

def consul_service_config(plugin_name, plugin_instance_name, ip, tags=[], port=80)
	{
		'id' => plugin_instance_name,
		'name' => plugin_name,
		'tags' => tags,
		'port' => port,
		'token' => plugin_instance_name,
		'checks' => [
			{
				'id' => plugin_name,
				'name' => "HTTP on port #{port}",
				'http' => "http://#{ip}:#{port}/health",
				'interval' => '10s',
				'timeout' => '1s'
			}
		]
	}
end

#register_service(consul_config) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/odania/service.rb', line 3

def register_service(consul_config)
	if Diplomat::Service.register consul_config
		puts 'Service registered'
	else
		puts 'Error registering service'
	end
end