arya-mongrel_proctitle 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongrel_proctitle.rb +26 -6
- metadata +1 -1
data/lib/mongrel_proctitle.rb
CHANGED
@@ -12,8 +12,16 @@ module Mongrel
|
|
12
12
|
@request_threads = []
|
13
13
|
@queue_length = 0
|
14
14
|
@request_count = 0
|
15
|
+
@updater_thread = Thread.new do
|
16
|
+
while true
|
17
|
+
@mutex.synchronize do
|
18
|
+
set_request_list_title
|
19
|
+
end
|
20
|
+
sleep 0.1
|
21
|
+
end
|
22
|
+
end
|
15
23
|
end
|
16
|
-
|
24
|
+
|
17
25
|
# Returns port used in title.
|
18
26
|
def port
|
19
27
|
@port
|
@@ -57,13 +65,23 @@ module Mongrel
|
|
57
65
|
@request_threads.unshift(@request_threads.delete(running_thread)) if running_thread
|
58
66
|
# this isn't exact, but it works for most situations
|
59
67
|
end
|
60
|
-
|
68
|
+
now = Time.now.to_f
|
61
69
|
list = @request_threads.inject([]) do |str, thread|
|
62
|
-
str << "#{thread[:arrived_at]
|
70
|
+
str << "#{time_delta_abbriv(now - thread[:arrived_at])} #{thread[:request_str]}"
|
63
71
|
end.join(" | ")
|
64
72
|
self.title = "handling #{list}"
|
65
73
|
end
|
66
74
|
end
|
75
|
+
|
76
|
+
def time_delta_abbriv(delta)
|
77
|
+
if delta < 60
|
78
|
+
"%.1fs" % delta
|
79
|
+
elsif delta < 3600
|
80
|
+
"#{delta.to_i / 60}m#{delta.to_i % 60}s"
|
81
|
+
else
|
82
|
+
"#{delta.to_i / 3600}h#{(delta.to_i % 3600) / 60}m"
|
83
|
+
end
|
84
|
+
end
|
67
85
|
|
68
86
|
# Reports process as being idle.
|
69
87
|
def set_idle
|
@@ -84,9 +102,11 @@ module Mongrel
|
|
84
102
|
# path = "#{path[0, 60]}..." if path.length > 60
|
85
103
|
# Thread.current[:request_str] = "#{address}: #{method} #{path}"
|
86
104
|
Thread.current[:request_str] = "#{method} #{path}"
|
87
|
-
Thread.current[:arrived_at] = Time.now.
|
88
|
-
@
|
89
|
-
|
105
|
+
Thread.current[:arrived_at] = Time.now.to_f
|
106
|
+
@mutex.synchronize do
|
107
|
+
@request_threads.push(Thread.current)
|
108
|
+
set_request_list_title(Thread.current)
|
109
|
+
end
|
90
110
|
end
|
91
111
|
|
92
112
|
# Returns current title
|