Class: BundleRequests::RackMiddleware
- Inherits:
-
Object
- Object
- BundleRequests::RackMiddleware
- Defined in:
- lib/bundle_requests/rack_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config = {}) ⇒ RackMiddleware
constructor
A new instance of RackMiddleware.
-
#start_consumer(app, config) ⇒ Object
$configuration.
Constructor Details
#initialize(app, config = {}) ⇒ RackMiddleware
Returns a new instance of RackMiddleware.
4 5 6 7 |
# File 'lib/bundle_requests/rack_middleware.rb', line 4 def initialize(app, config={}) @app = app start_consumer(app, config) end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bundle_requests/rack_middleware.rb', line 21 def call env Rails.logger.info("request #{env['REQUEST_PATH']} #{Thread.current.name}") s = Time.now if env['REQUEST_PATH'] == $configuration['incoming_request'] Thread.current['request'] = env $waiting_threads << Thread.current puts "I am waiting #{Thread.current.object_id}" Thread.stop response = Thread.current['response'] else puts "[Not bundle api]" response = @app.call env end puts "TIME required for request to process is -#{Time.now - s} " response end |
#start_consumer(app, config) ⇒ Object
$configuration
13 14 15 16 17 18 19 |
# File 'lib/bundle_requests/rack_middleware.rb', line 13 def start_consumer(app, config) Mutex.new.synchronize do if @consumer.nil? @consumer = BundleRequests::Consumer.new(app, config) # cretes new infinite thread end end end |