rack-timeout 0.3.0 → 0.3.1

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: 5a270fccd2075f0f8333041b5bfbbc5c3fdf2c4c
4
- data.tar.gz: 41588cd9b9e1fbfce990852177cb5ec7b284de0d
3
+ metadata.gz: 3011645170de523349a1928ac09ee55825019f0b
4
+ data.tar.gz: 17fcae3abe9f9cf37391a6381a795c142791cde5
5
5
  SHA512:
6
- metadata.gz: 0768903ea52e7c2eeabd4140e1bebebe5d24f608e9c03ad1482c65f14d468d2cabd59bc2165502d3255005b420bc91c2797151fabb5483004d04d448569161e6
7
- data.tar.gz: d6fb9a424a79dcbdc745b2d1b7be2718ef9baee6b9c22e4ba59e91e3446c64243a99c41424da91929668d2583c21c3284cb2d3e30ebd5a569ad84e61e03730fe
6
+ metadata.gz: 6eac121daa70934e450db7320a92544840bcc0adba0a38539af380394ac239b546fb428daefa0544a372bff20627f704dfe1ae4415ee99085de1b987b7af35c8
7
+ data.tar.gz: 7db38b0f4e1b4d9e2678de2efc867efd2b3381cb615dccf1d365f766576b08107a4d8bc7c2e1fdaf18846a912e88c8ba07862999a86002d7aa1046121b3e886b
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.1
2
+ =====
3
+ - Rollbar module improvements
4
+
1
5
  0.3.0
2
6
  =====
3
7
  - use a single scheduler thread to manage timeouts, instead of one timeout thread per request
@@ -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
- update_service = ->(status = :active) {
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) { update_service.call :active }
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
- update_service.call :timed_out
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
- update_service.call :completed
131
+ register_state_change.call :completed
132
132
  response
133
133
  end
134
134
 
@@ -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 data unless data.respond_to? :[]=
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.0
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-02 00:00:00.000000000 Z
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.