Class: RubyPitaya::EtcdConnector
- Inherits:
-
Object
- Object
- RubyPitaya::EtcdConnector
- Defined in:
- lib/rubypitaya/core/etcd_connector.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(server_uuid, desktop_name, server_name, etcd_prefix, etcd_address, allow_reconnect, lease_seconds, log) ⇒ EtcdConnector
constructor
A new instance of EtcdConnector.
Constructor Details
#initialize(server_uuid, desktop_name, server_name, etcd_prefix, etcd_address, allow_reconnect, lease_seconds, log) ⇒ EtcdConnector
Returns a new instance of EtcdConnector.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rubypitaya/core/etcd_connector.rb', line 8 def initialize(server_uuid, desktop_name, server_name, etcd_prefix, etcd_address, allow_reconnect, lease_seconds, log) @server_uuid = server_uuid @server_name = server_name @desktop_name = desktop_name @etcd_prefix = etcd_prefix @etcd_address = etcd_address @allow_reconnect = allow_reconnect @lease_seconds = lease_seconds @log = log @renew_connection_seconds = lease_seconds / 2.0 @renew_connection_key = nil @renew_connection_value = nil @renew_connection_thread = nil end |
Instance Method Details
#connect ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rubypitaya/core/etcd_connector.rb', line 26 def connect connection_key = get_connection_key connection_value = get_connection_value @connection = Etcdv3.new(endpoints: @etcd_address, allow_reconnect: @allow_reconnect) @lease = @connection.lease_grant(@lease_seconds) @connection.put(connection_key, connection_value, lease: @lease.ID) @renew_connection_key = connection_key @renew_connection_value = connection_value renew_connection end |
#disconnect ⇒ Object
43 44 45 46 |
# File 'lib/rubypitaya/core/etcd_connector.rb', line 43 def disconnect stop_renew_connection @connection.del(get_connection_key) end |