slowpoke 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e81989e90c4ba519f36f46021d180d1f2e5df40
4
- data.tar.gz: ba0a6e166d707381fe6ebbaa8ddf8e8253f96eb9
3
+ metadata.gz: af786e335277355221963f452414cadd17d53fec
4
+ data.tar.gz: cfdce56d500d599f5d854bb68a44b86f03e6a4b1
5
5
  SHA512:
6
- metadata.gz: 22e578b270ebbe71cb328b219d540463b34f21c6e4eb38095d0a56c2f7f18bd0e901d48e1a5d142eb6abd40f4468cda90f542a97117495588410127b06612d17
7
- data.tar.gz: aea0511a75fbadb6e892e34f3a9cb1fee7f9c74999082f62106aaa9a6586375cf2629880bac0c4ec570c2e228d1d004bf1214f2542ff0248c1f1fdfbdaf58792
6
+ metadata.gz: b93df7d6d424bc941c37a7451cc6c63783cb9a390b08941907f1e8187f31a3a1c328d6e017e661c1b94fabb333260d2c0c0dbc6225e44b4bba78125fdd6d64c9
7
+ data.tar.gz: 7447ac2e09c6bd908b0ff9b81ef4ec28b0e73eb14a9ac201d94e85c7bb2dc39e85ac4860af73c358f52f7f5bfdabd4321a5c739108986a3ac683932979e74913
@@ -2,7 +2,8 @@ module Slowpoke
2
2
  class Railtie < Rails::Railtie
3
3
 
4
4
  initializer "slowpoke" do
5
- Slowpoke.timeout = (ENV["TIMEOUT"] || 15).to_i
5
+ Rack::Timeout.timeout = Slowpoke.timeout
6
+ ActiveRecord::Base.logger.class.send(:include, ::LoggerSilence) if ActiveRecord::Base.logger
6
7
  end
7
8
 
8
9
  end
@@ -1,3 +1,3 @@
1
1
  module Slowpoke
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/slowpoke.rb CHANGED
@@ -9,16 +9,19 @@ require "action_dispatch/middleware/exception_wrapper"
9
9
 
10
10
  module Slowpoke
11
11
  class << self
12
- attr_reader :timeout
13
12
  attr_accessor :database_timeout
14
13
  end
15
14
 
15
+ def self.timeout
16
+ @timeout ||= (ENV["TIMEOUT"] || 15).to_i
17
+ end
18
+
16
19
  def self.timeout=(timeout)
17
- @timeout = timeout
18
- Rack::Timeout.timeout = timeout
20
+ @timeout = Rack::Timeout.timeout = timeout
19
21
  end
20
22
  end
21
23
 
24
+ # remove noisy logger
22
25
  Rack::Timeout.unregister_state_change_observer(:logger)
23
26
 
24
27
  ActionDispatch::ExceptionWrapper.rescue_responses["Rack::Timeout::RequestTimeoutError"] = :service_unavailable
@@ -34,17 +37,24 @@ class ActionView::Template
34
37
 
35
38
  end
36
39
 
40
+ # notifications
37
41
  class ActionController::Base
38
42
 
39
43
  def rescue_from_timeout(exception)
40
44
  ActiveSupport::Notifications.instrument("timeout.slowpoke", {})
45
+
46
+ # extremely important
47
+ # protect the process with a restart
48
+ # https://github.com/heroku/rack-timeout/issues/39
49
+ Process.kill "QUIT", Process.pid
50
+
41
51
  raise exception
42
52
  end
43
53
  rescue_from Rack::Timeout::Error, with: :rescue_from_timeout
44
54
 
45
55
  end
46
56
 
47
- # timeout queries after a minute
57
+ # database timeout
48
58
  class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
49
59
 
50
60
  def configure_connection_with_statement_timeout
@@ -52,7 +62,6 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
52
62
  safely do
53
63
  timeout = Slowpoke.database_timeout || Slowpoke.timeout
54
64
  if ActiveRecord::Base.logger
55
- ActiveRecord::Base.logger.class.send(:include, ::LoggerSilence)
56
65
  ActiveRecord::Base.logger.silence do
57
66
  execute("SET statement_timeout = #{timeout * 1000}")
58
67
  end
data/slowpoke.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "rack-timeout", "= 0.1.0beta3"
21
+ spec.add_dependency "rack-timeout", ">= 0.1.0"
22
22
  spec.add_dependency "robustly"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slowpoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: rack-timeout
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0beta3
19
+ version: 0.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0beta3
26
+ version: 0.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: robustly
29
29
  requirement: !ruby/object:Gem::Requirement