rack-timeout 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/rack/timeout/core.rb +14 -14
- data/lib/rack/timeout/rollbar.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3011645170de523349a1928ac09ee55825019f0b
|
4
|
+
data.tar.gz: 17fcae3abe9f9cf37391a6381a795c142791cde5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eac121daa70934e450db7320a92544840bcc0adba0a38539af380394ac239b546fb428daefa0544a372bff20627f704dfe1ae4415ee99085de1b987b7af35c8
|
7
|
+
data.tar.gz: 7db38b0f4e1b4d9e2678de2efc867efd2b3381cb615dccf1d365f766576b08107a4d8bc7c2e1fdaf18846a912e88c8ba07862999a86002d7aa1046121b3e886b
|
data/CHANGELOG
CHANGED
data/lib/rack/timeout/core.rb
CHANGED
@@ -106,29 +106,29 @@ module Rack
|
|
106
106
|
info.timeout = RT.service_timeout # nice and simple, when service_past_wait is true, not so much otherwise:
|
107
107
|
info.timeout = seconds_service_left if !RT.service_past_wait && seconds_service_left && seconds_service_left > 0 && seconds_service_left < RT.service_timeout
|
108
108
|
|
109
|
-
RT._set_state! env, :ready
|
109
|
+
RT._set_state! env, :ready # we're good to go, but have done nothing yet
|
110
110
|
|
111
|
-
heartbeat_event = nil
|
112
|
-
|
113
|
-
heartbeat_event.cancel! if status != :active
|
114
|
-
info.service = Time.now - time_started_service
|
115
|
-
RT._set_state! env, status
|
111
|
+
heartbeat_event = nil # init var so it's in scope for following proc
|
112
|
+
register_state_change = ->(status = :active) { # updates service time and state; will run every second
|
113
|
+
heartbeat_event.cancel! if status != :active # if the request is no longer active we should stop updating every second
|
114
|
+
info.service = Time.now - time_started_service # update service time
|
115
|
+
RT._set_state! env, status # update status
|
116
116
|
}
|
117
|
-
heartbeat_event = RT::Scheduler.run_every(1) {
|
117
|
+
heartbeat_event = RT::Scheduler.run_every(1) { register_state_change.call :active } # start updating every second while active; if log level is debug, this will log every sec
|
118
118
|
|
119
|
-
timeout = RT::Scheduler::Timeout.new do |app_thread|
|
120
|
-
|
119
|
+
timeout = RT::Scheduler::Timeout.new do |app_thread| # creates a timeout instance responsible for timing out the request. the given block runs if timed out
|
120
|
+
register_state_change.call :timed_out
|
121
121
|
app_thread.raise(RequestTimeoutException.new(env), "Request #{"waited #{info.ms(:wait)}, then " if info.wait}ran for longer than #{info.ms(:timeout)}")
|
122
122
|
end
|
123
123
|
|
124
|
-
response = timeout.timeout(info.timeout) do
|
125
|
-
begin @app.call(env)
|
126
|
-
rescue RequestTimeoutException => e
|
127
|
-
raise RequestTimeoutError.new(env), e.message, e.backtrace
|
124
|
+
response = timeout.timeout(info.timeout) do # perform request with timeout
|
125
|
+
begin @app.call(env) # boom, send request down the middleware chain
|
126
|
+
rescue RequestTimeoutException => e # will actually hardly ever get to this point because frameworks tend to catch this. see README for more
|
127
|
+
raise RequestTimeoutError.new(env), e.message, e.backtrace # but in case it does get here, re-reaise RequestTimeoutException as RequestTimeoutError
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
|
131
|
+
register_state_change.call :completed
|
132
132
|
response
|
133
133
|
end
|
134
134
|
|
data/lib/rack/timeout/rollbar.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative "core"
|
|
5
5
|
# require "rack/timeout/rollbar"
|
6
6
|
#
|
7
7
|
# This is somewhat experimental and very lightly tested.
|
8
|
+
#
|
9
|
+
# Ruby 2.0 is required as we use Module.prepend
|
8
10
|
|
9
11
|
module Rack::Timeout::Rollbar
|
10
12
|
def build_payload(level, message, exception, extra)
|
@@ -14,9 +16,12 @@ module Rack::Timeout::Rollbar
|
|
14
16
|
return payload unless payload.respond_to? :[]
|
15
17
|
|
16
18
|
data = payload["data"]
|
17
|
-
return
|
19
|
+
return payload unless data.respond_to? :[]=
|
18
20
|
|
19
21
|
request = ::Rack::Request.new(exception.env)
|
22
|
+
payload = payload.dup
|
23
|
+
data = data.dup
|
24
|
+
payload["data"] = data
|
20
25
|
|
21
26
|
data["fingerprint"] = [
|
22
27
|
exception.class.name,
|
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.3.
|
4
|
+
version: 0.3.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-09-
|
11
|
+
date: 2015-09-03 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.
|