rack-timeout 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +31 -15
  3. data/lib/rack/timeout.rb +2 -2
  4. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a99f11768e4de71a88bbc6eafa4bbb5817cf639
4
- data.tar.gz: 1e5d53984df8f0152c945a9dd2d19a0c60a0b78a
3
+ metadata.gz: 5c350e40f59d01af35e44aa9caebf66752f30e15
4
+ data.tar.gz: f5f0133eb613f110cff035afee6dd512eb0a0d10
5
5
  SHA512:
6
- metadata.gz: ae467f02c8ceefed9e53a40214595a9e3daa2f28b71500b1f28230e322f420e07b1f0bac83b0115e9dae8b13df4100bd734d64b007959e697afb773530286633
7
- data.tar.gz: 5926a3baff52db4aa3bb7a2c63c3c988431820565faaef508e2420f34ae1b8ca86b0b09762d229dadb215308a007c1116344c9bf607f788a7ace13487d71225f
6
+ metadata.gz: 805fe810b977eb29867df02daac8f10eeb28344c57fa8bb1d91ee3a45dc3fd6a59d525db64986f0a3f51d27923dc48c95ef3bcd0ecf838bf03106aa8ef95ab4d
7
+ data.tar.gz: 704345ef0762eb668eb3a6a8d0ef08c3e4cfad85a6aad0ab332986afc1cd6b52d72e6b785b57cb64f502fc1dd0c652747b34ab557eb30eeabf50e0b022a82253
@@ -17,20 +17,26 @@ The following covers currently supported versions of Rails, Rack, Ruby, and Bund
17
17
 
18
18
  ### Rails apps
19
19
 
20
- # Gemfile
21
- gem "rack-timeout"
20
+ ```ruby
21
+ # Gemfile
22
+ gem "rack-timeout"
23
+ ```
22
24
 
23
25
  That's all that's required if you want to use the default timeout of 15s. To use a custom timeout, create an initializer file:
24
26
 
25
- # config/initializers/timeout.rb
26
- Rack::Timeout.timeout = 5 # seconds
27
+ ```ruby
28
+ # config/initializers/timeout.rb
29
+ Rack::Timeout.timeout = 5 # seconds
30
+ ```
27
31
 
28
32
  ### Sinatra and other Rack apps
29
33
 
30
- # config.ru
31
- require "rack-timeout"
32
- use Rack::Timeout # Call as early as possible so rack-timeout runs before all other middleware.
33
- Rack::Timeout.timeout = 5 # Recommended. If omitted, defaults to 15 seconds.
34
+ ```ruby
35
+ # config.ru
36
+ require "rack-timeout"
37
+ use Rack::Timeout # Call as early as possible so rack-timeout runs before all other middleware.
38
+ Rack::Timeout.timeout = 5 # Recommended. If omitted, defaults to 15 seconds.
39
+ ```
34
40
 
35
41
 
36
42
  The Rabbit Hole
@@ -168,13 +174,17 @@ Observers are blocks that are notified about state changes during a request's li
168
174
 
169
175
  You can register an observer with:
170
176
 
171
- Rack::Timeout.register_state_change_observer(:a_unique_name) { |env| do_things env }
177
+ ```ruby
178
+ Rack::Timeout.register_state_change_observer(:a_unique_name) { |env| do_things env }
179
+ ```
172
180
 
173
181
  There's currently no way to subscribe to changes into or out of a particular state. To check the actual state we're moving into, read `env['rack-timeout.info'].state`. Handling going out of a state would require some additional logic in the observer.
174
182
 
175
183
  You can remove an observer with `unregister_state_change_observer`:
176
184
 
177
- Rack::Timeout.unregister_state_change_observer(:a_unique_name)
185
+ ```ruby
186
+ Rack::Timeout.unregister_state_change_observer(:a_unique_name)
187
+ ```
178
188
 
179
189
 
180
190
  rack-timeout's logging is implemented using an observer; see `Rack::Timeout::StageChangeLoggingObserver` in logger.rb for the implementation.
@@ -193,21 +203,27 @@ Rack::Timeout will try to use `Rails.logger` if present, otherwise it'll look fo
193
203
 
194
204
  A custom logger can be set via `Rack::Timeout::StageChangeLoggingObserver.logger`. This takes priority over the automatic logger detection:
195
205
 
196
- Rack::Timeout::StageChangeLoggingObserver.logger = Logger.new
206
+ ```ruby
207
+ Rack::Timeout::StageChangeLoggingObserver.logger = Logger.new
208
+ ```
197
209
 
198
210
  When creating its own logger, rack-timeout will use a log level of `INFO`. Otherwise whatever log level is already set on the logger being used continues in effect.
199
211
 
200
212
  Logging is enabled by default if Rack::Timeout is loaded via the `rack-timeout` file (recommended), but can be removed by unregistering its observer:
201
213
 
202
- Rack::Timeout.unregister_state_change_observer(:logger)
214
+ ```ruby
215
+ Rack::Timeout.unregister_state_change_observer(:logger)
216
+ ```
203
217
 
204
218
  Each log line is a set of `key=value` pairs, containing the entries from the `env["rack-timeout.info"]` struct that are not `nil`. See the Request Lifetime section above for a description of each field. Note that while the values for `wait`, `timeout`, and `service` are stored internally as seconds, they are logged as milliseconds for readability.
205
219
 
206
220
  A sample log excerpt might look like:
207
221
 
208
- source=rack-timeout id=13793c wait=369ms timeout=10000ms state=ready at=info
209
- source=rack-timeout id=13793c wait=369ms timeout=10000ms service=15ms state=completed at=info
210
- source=rack-timeout id=ea7bd3 wait=371ms timeout=10000ms state=timed_out at=error
222
+ ```
223
+ source=rack-timeout id=13793c wait=369ms timeout=10000ms state=ready at=info
224
+ source=rack-timeout id=13793c wait=369ms timeout=10000ms service=15ms state=completed at=info
225
+ source=rack-timeout id=ea7bd3 wait=371ms timeout=10000ms state=timed_out at=error
226
+ ```
211
227
 
212
228
 
213
229
  Compatibility
@@ -80,7 +80,7 @@ module Rack
80
80
  info.wait, info.timeout = seconds_waited, final_wait_timeout # updating the info properties; info.timeout will be the wait timeout at this point
81
81
  if seconds_service_left <= 0 # expire requests that have waited for too long in the queue (as they are assumed to have been dropped by the web server / routing layer at this point)
82
82
  RT._set_state! env, :expired
83
- raise RequestExpiryError, "Request older than #{final_wait_timeout} seconds."
83
+ raise RequestExpiryError, "Request older than #{info.ms(:timeout)}."
84
84
  end
85
85
  end
86
86
 
@@ -103,7 +103,7 @@ module Rack
103
103
  sleep(sleep_seconds)
104
104
  end
105
105
  RT._set_state! env, :timed_out
106
- app_thread.raise(RequestTimeoutError, "Request #{"waited #{info.ms(:wait)} seconds, then " if info.wait}ran for longer than #{info.ms(:timeout)}")
106
+ app_thread.raise(RequestTimeoutError, "Request #{"waited #{info.ms(:wait)}, then " if info.wait}ran for longer than #{info.ms(:timeout)}")
107
107
  end
108
108
  response = @app.call(env)
109
109
  ensure
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caio Chassot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-03-12 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.
@@ -42,8 +42,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  version: '0'
43
43
  requirements: []
44
44
  rubyforge_project:
45
- rubygems_version: 2.2.2
45
+ rubygems_version: 2.4.5
46
46
  signing_key:
47
47
  specification_version: 4
48
48
  summary: Abort requests that are taking too long
49
49
  test_files: []
50
+ has_rdoc: