Class: RackProctitle
- Inherits:
-
Object
- Object
- RackProctitle
- Defined in:
- lib/rack_proctitle.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = nil) ⇒ RackProctitle
constructor
A new instance of RackProctitle.
Constructor Details
#initialize(app, options = nil) ⇒ RackProctitle
Returns a new instance of RackProctitle.
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rack_proctitle.rb', line 2 def initialize(app, = nil) @app = app @title = "#{( && .delete(:prefix)) || 'rack'}" @title << "/#{APPLICATION_VERSION}" if defined?(APPLICATION_VERSION) @title << " [%d/%d]: %s" @mutex = Mutex.new @request_threads = [] @total_request_count = 0 start_updater_thread end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rack_proctitle.rb', line 16 def call(env) ensure_updater_thread_running Thread.current[:request_str] = ((env["REQUEST_URI"].nil? || env["REQUEST_URI"].empty?) ? "/" : env["REQUEST_URI"]).split("?", 2)[0] Thread.current[:arrived_at] = Time.now.to_f @mutex.synchronize do @request_threads.push(Thread.current) set_request_list_title end begin @app.call(env) ensure @mutex.synchronize do @total_request_count += 1 @last_time = Time.now.to_f - Thread.current[:arrived_at].to_f @last_request_str = Thread.current[:request_str].to_s @request_threads.delete(Thread.current) set_request_list_title end end end |