Class: Influxdb::Api::Client::Connection
- Inherits:
-
Object
- Object
- Influxdb::Api::Client::Connection
- Defined in:
- lib/influxdb/api/client/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#dead_since ⇒ Object
readonly
Returns the value of attribute dead_since.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #alive! ⇒ Object
- #dead! ⇒ Object
- #dead? ⇒ Boolean
- #full_path(path, params = {}) ⇒ Object
- #healthy! ⇒ Object
-
#initialize(host, connection, config = Influxdb::Api.config) ⇒ Connection
constructor
A new instance of Connection.
- #resurrect! ⇒ Object
- #resurrectable? ⇒ Boolean
- #to_s ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/influxdb/api/client/connection.rb', line 5 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/influxdb/api/client/connection.rb', line 5 def connection @connection end |
#dead_since ⇒ Object (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 |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
5 6 7 |
# File 'lib/influxdb/api/client/connection.rb', line 5 def failures @failures end |
#host ⇒ Object (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
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
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_s ⇒ Object
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 |