Class: InfluxDB::Writer::Async
- Inherits:
-
Object
- Object
- InfluxDB::Writer::Async
- Defined in:
- lib/influxdb/writer/async.rb
Defined Under Namespace
Classes: Worker
Constant Summary collapse
- WORKER_MUTEX =
Mutex.new
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(client, config) ⇒ Async
constructor
A new instance of Async.
- #worker ⇒ Object
- #write(data, _precision = nil, _retention_policy = nil, _database = nil) ⇒ Object
Constructor Details
#initialize(client, config) ⇒ Async
Returns a new instance of Async.
10 11 12 13 |
# File 'lib/influxdb/writer/async.rb', line 10 def initialize(client, config) @client = client @config = config end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/influxdb/writer/async.rb', line 8 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/influxdb/writer/async.rb', line 8 def config @config end |
Instance Method Details
#worker ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/influxdb/writer/async.rb', line 21 def worker return @worker if @worker WORKER_MUTEX.synchronize do # this return is necessary because the previous mutex holder # might have already assigned the @worker return @worker if @worker @worker = Worker.new(client, config) end end |
#write(data, _precision = nil, _retention_policy = nil, _database = nil) ⇒ Object
15 16 17 18 |
# File 'lib/influxdb/writer/async.rb', line 15 def write(data, _precision = nil, _retention_policy = nil, _database = nil) data = data.is_a?(Array) ? data : [data] data.map { |p| worker.push(p) } end |