Class: EsReadModel::RackSubscriber
- Inherits:
-
Object
- Object
- EsReadModel::RackSubscriber
- Defined in:
- lib/es_readmodel/rack_subscriber.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ RackSubscriber
constructor
A new instance of RackSubscriber.
Constructor Details
#initialize(app, options) ⇒ RackSubscriber
Returns a new instance of RackSubscriber.
11 12 13 14 15 16 |
# File 'lib/es_readmodel/rack_subscriber.rb', line 11 def initialize(app, ) @app = app @listener = [:listener] @subscriber = Subscriber.new() Thread.new { @subscriber.subscribe } end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/es_readmodel/rack_subscriber.rb', line 9 def status @status end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/es_readmodel/rack_subscriber.rb', line 18 def call(env) @request = Rack::Request.new(env) if env['PATH_INFO'] == '/status' status, headers, body = json_response(200, @subscriber.status) else env['readmodel.state'] = @subscriber.state env['readmodel.available'] = @subscriber.status[:available] env['readmodel.status'] = 'OK' status, headers, body = @app.call(env) end @listener.call({ level: 'info', tag: 'http.request', msg: "#{env['REQUEST_METHOD']} #{@request.fullpath}", status: status }) [status, headers, body] end |