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.
- #stop! ⇒ Object
- #stopped? ⇒ Boolean
- #worker ⇒ Object
- #write(data, precision = nil, retention_policy = nil, database = nil) ⇒ Object
Constructor Details
#initialize(client, config) ⇒ Async
Returns a new instance of Async.
9 10 11 12 13 |
# File 'lib/influxdb/writer/async.rb', line 9 def initialize(client, config) @client = client @config = config @stopped = false end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/influxdb/writer/async.rb', line 7 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/influxdb/writer/async.rb', line 7 def config @config end |
Instance Method Details
#stop! ⇒ Object
19 20 21 22 |
# File 'lib/influxdb/writer/async.rb', line 19 def stop! worker.stop! @stopped = true end |
#stopped? ⇒ Boolean
15 16 17 |
# File 'lib/influxdb/writer/async.rb', line 15 def stopped? @stopped end |
#worker ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/influxdb/writer/async.rb', line 30 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
24 25 26 27 |
# File 'lib/influxdb/writer/async.rb', line 24 def write(data, precision = nil, retention_policy = nil, database = nil) data = data.is_a?(Array) ? data : [data] data.map { |payload| worker.push(payload, precision, retention_policy, database) } end |