Class: Influxdb::Api::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/influxdb/api/client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, connection, config = Influxdb::Api.config) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
12
# File 'lib/influxdb/api/client/connection.rb', line 7

def initialize(host, connection, config = Influxdb::Api.config)
  @config = config
  @host = host
  @connection = connection
  @failures = 0
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/influxdb/api/client/connection.rb', line 5

def config
  @config
end

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/influxdb/api/client/connection.rb', line 5

def connection
  @connection
end

#dead_sinceObject (readonly)

Returns the value of attribute dead_since.



5
6
7
# File 'lib/influxdb/api/client/connection.rb', line 5

def dead_since
  @dead_since
end

#failuresObject (readonly)

Returns the value of attribute failures.



5
6
7
# File 'lib/influxdb/api/client/connection.rb', line 5

def failures
  @failures
end

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/influxdb/api/client/connection.rb', line 5

def host
  @host
end

Instance Method Details

#alive!Object



29
30
31
32
# File 'lib/influxdb/api/client/connection.rb', line 29

def alive!
  @dead = false
  self
end

#dead!Object



22
23
24
25
26
27
# File 'lib/influxdb/api/client/connection.rb', line 22

def dead!
  @dead = true
  @failures += 1
  @dead_since = Time.now
  self
end

#dead?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/influxdb/api/client/connection.rb', line 18

def dead?
  !!@dead
end

#full_path(path, params = {}) ⇒ Object



14
15
16
# File 'lib/influxdb/api/client/connection.rb', line 14

def full_path(path, params={})
  path + (params.empty? ? '' : "?#{::Faraday::Utils::ParamsHash[params].to_query}")
end

#healthy!Object



34
35
36
37
38
# File 'lib/influxdb/api/client/connection.rb', line 34

def healthy!
  @dead = false
  @failures = 0
  self
end

#resurrect!Object



40
41
42
43
# File 'lib/influxdb/api/client/connection.rb', line 40

def resurrect!
  alive! if resurrectable?
  self
end

#resurrectable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/influxdb/api/client/connection.rb', line 45

def resurrectable?
  Time.now > dead_since + (config.resurrect_timeout * 2 ** (failures - 1))
end

#to_sObject



49
50
51
# File 'lib/influxdb/api/client/connection.rb', line 49

def to_s
  "<#{self.class.name} host: #{host} (#{dead? ? 'dead since ' + dead_since.to_s : 'alive'})>"
end