rack-timeout 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84c611398a87d61130bbda91d3b98407a42b5906
4
- data.tar.gz: 824bf643c7817f626c4a1f523b346b41a30ea97c
3
+ metadata.gz: 738562ce41045bc02a6cdf9ffb7333c6bdd73247
4
+ data.tar.gz: c665463483d072eda397c6ad9056d3ba2073f7ef
5
5
  SHA512:
6
- metadata.gz: c9d4f5e73090c55c0656c1880a0cd36eda06e062bf24989fb6d9a8eba290ab708b6c8a66646864ba780e37b16b9f391a250b53bfa029834a409d2e29afe80ac0
7
- data.tar.gz: 73b9e72dd731472638cbb330582b6b93bd958809de61167e41f3fb138f4559c147ad6cf79e1b1c36a9318e5017e07b1a45d47f2e8dfbb04724e436323cc6d94e
6
+ metadata.gz: ffefe99a1089a25cd504cd88e3dbc4bf4a834bf08b982ad97aa09057ba5e03871f38e5ed36bf65ba256a1f7456e429858ff6a796bee3a90069c9dc0e3dbb38c9
7
+ data.tar.gz: 1b6e1b54a34fa911e21bfdefefde66f3d74c75a590cb42642cf9bdc512bdb5558ef987815f7943edf069567fb7574f7c982ef87c09ca5fb28101c3ab4ef03742
data/lib/rack/timeout.rb CHANGED
@@ -13,7 +13,11 @@ module Rack
13
13
  :service, # time rack spent processing the request (updated ~ every second)
14
14
  :timeout, # the actual computed timeout to be used for this request
15
15
  :state, # the request's current state, see below:
16
- )
16
+ ) {
17
+ def ms(k) # helper method used for formatting values in milliseconds
18
+ '%.fms' % (self[k] * 1000) if self[k]
19
+ end
20
+ }
17
21
  VALID_STATES = [
18
22
  :expired, # The request was too old by the time it reached rack (see wait_timeout, wait_overtime)
19
23
  :ready, # We're about to start processing this request
@@ -99,7 +103,7 @@ module Rack
99
103
  sleep(sleep_seconds)
100
104
  end
101
105
  RT._set_state! env, :timed_out
102
- app_thread.raise(RequestTimeoutError, "Request ran for longer than #{info.timeout} seconds.")
106
+ app_thread.raise(RequestTimeoutError, "Request #{"waited #{info.ms(:wait)} seconds, then " if info.wait}ran for longer than #{info.ms(:timeout)}")
103
107
  end
104
108
  response = @app.call(env)
105
109
  ensure
@@ -39,22 +39,17 @@ class Rack::Timeout
39
39
  (@fallback_logger ||= self.class.mk_logger($stderr))
40
40
  end
41
41
 
42
- # helper method used for formatting in #log_state_change
43
- def ms(s)
44
- '%.fms' % (s * 1000)
45
- end
46
-
47
42
  # generates the actual log string
48
43
  def log_state_change(env)
49
44
  info = env[ENV_INFO_KEY]
50
45
  level = STATE_LOG_LEVEL[info.state]
51
46
  logger(env).send(level) do
52
47
  s = 'source=rack-timeout'
53
- s << ' id=' << info.id if info.id
54
- s << ' wait=' << ms(info.wait) if info.wait
55
- s << ' timeout=' << ms(info.timeout) if info.timeout
56
- s << ' service=' << ms(info.service) if info.service
57
- s << ' state=' << info.state.to_s if info.state
48
+ s << ' id=' << info.id if info.id
49
+ s << ' wait=' << info.ms(:wait) if info.wait
50
+ s << ' timeout=' << info.ms(:timeout) if info.timeout
51
+ s << ' service=' << info.ms(:service) if info.service
52
+ s << ' state=' << info.state.to_s if info.state
58
53
  s
59
54
  end
60
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Chassot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rack middleware which aborts requests that have been running for longer
14
14
  than a specified timeout.