slowpoke 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slowpoke/railtie.rb +2 -1
- data/lib/slowpoke/version.rb +1 -1
- data/lib/slowpoke.rb +14 -5
- data/slowpoke.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af786e335277355221963f452414cadd17d53fec
|
4
|
+
data.tar.gz: cfdce56d500d599f5d854bb68a44b86f03e6a4b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b93df7d6d424bc941c37a7451cc6c63783cb9a390b08941907f1e8187f31a3a1c328d6e017e661c1b94fabb333260d2c0c0dbc6225e44b4bba78125fdd6d64c9
|
7
|
+
data.tar.gz: 7447ac2e09c6bd908b0ff9b81ef4ec28b0e73eb14a9ac201d94e85c7bb2dc39e85ac4860af73c358f52f7f5bfdabd4321a5c739108986a3ac683932979e74913
|
data/lib/slowpoke/railtie.rb
CHANGED
@@ -2,7 +2,8 @@ module Slowpoke
|
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
|
4
4
|
initializer "slowpoke" do
|
5
|
-
|
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
|
data/lib/slowpoke/version.rb
CHANGED
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
|
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", "
|
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.
|
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.
|
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.
|
26
|
+
version: 0.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: robustly
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|