Class: SidekiqQueueStatus::Middleware
- Inherits:
-
Object
- Object
- SidekiqQueueStatus::Middleware
- Defined in:
- lib/sidekiq_queue_status/middleware.rb
Constant Summary collapse
- HEADERS =
{ 'Content-Type' => 'application/json', 'Cache-Control' => 'no-cache' }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
10 11 12 |
# File 'lib/sidekiq_queue_status/middleware.rb', line 10 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sidekiq_queue_status/middleware.rb', line 14 def call(env) if env["PATH_INFO"] =~ %r{\A/queue-status\Z} metrics = Metric.all body = { latencies: metrics.latencies, failure_percentage: metrics.failure_rate, errors: metrics.errors }.to_json status = metrics.errors.any? ? 503 : 200 [status, HEADERS, [body]] else @app.call(env) end end |