Class: Rack::InfluxDB
- Inherits:
-
Object
- Object
- Rack::InfluxDB
- Defined in:
- lib/rack/influxdb.rb,
lib/rack/influxdb/version.rb,
lib/rack/influxdb/configuration.rb
Overview
The InfluxDB rack middleware class.
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- DEFAULT_QUEUE_SIZE =
Caps how many computed points can be buffered while waiting to be written. If InfluxDB becomes slow or unreachable, the queue fills up and further points are dropped (see #enqueue) instead of growing without bound or blocking requests.
1_000- VERSION =
'0.2.0'
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ InfluxDB
constructor
A new instance of InfluxDB.
-
#shutdown ⇒ Object
Stops accepting new points and waits (briefly) for the worker to drain whatever is already queued.
Constructor Details
#initialize(app) ⇒ InfluxDB
Returns a new instance of InfluxDB.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rack/influxdb.rb', line 25 def initialize(app) @app = app @queue = SizedQueue.new(DEFAULT_QUEUE_SIZE) @worker_mutex = Mutex.new @worker = nil # Flush whatever is left in the queue when the process exits (e.g. on # a graceful Puma shutdown), so the last few requests before shutdown # aren't silently lost. This never blocks a request, only exit. at_exit { shutdown } end |
Class Method Details
.configuration ⇒ Object
16 17 18 |
# File 'lib/rack/influxdb.rb', line 16 def configuration @configuration ||= Rack::InfluxDB::Configuration.new end |
.configure {|configuration| ... } ⇒ Object
20 21 22 |
# File 'lib/rack/influxdb.rb', line 20 def configure yield(configuration) end |
Instance Method Details
#call(env) ⇒ Object
37 38 39 |
# File 'lib/rack/influxdb.rb', line 37 def call(env) @app.call(env).tap { |response| write_request(env, response) } end |
#shutdown ⇒ Object
Stops accepting new points and waits (briefly) for the worker to drain whatever is already queued. Safe to call multiple times and safe to call even if the worker was never started.
44 45 46 47 |
# File 'lib/rack/influxdb.rb', line 44 def shutdown @queue.close unless @queue.closed? @worker&.join(5) end |