slowpoke 0.0.6 → 0.1.0
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/Gemfile +2 -0
- data/README.md +22 -26
- data/lib/slowpoke.rb +1 -15
- data/lib/slowpoke/railtie.rb +5 -2
- data/lib/slowpoke/version.rb +1 -1
- data/slowpoke.gemspec +1 -0
- metadata +16 -3
- data/lib/slowpoke/postgres.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29835ce4edb81b06635ee82405908c32d490623a
|
4
|
+
data.tar.gz: 8653542563bcee20f8c5288b327a2bc6337f707b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24ee1b1e5f943bbc462a0f3ace64178f2a5ae9bf219fce257e4d97193e760179babc07bb80d79bddeca82343f68a0e2b158a9510dee91f22e943e67e7498024
|
7
|
+
data.tar.gz: bc81cadcc3aaa7b54bf549e84d79c1e773f91895b3a795f4fd69e3f34845753f24358204a22c625d720fdcb98f9db08b43a526d14d58d3c01e0f8c1554239498
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Slowpoke
|
2
2
|
|
3
|
-
|
3
|
+
[Rack::Timeout](https://github.com/heroku/rack-timeout) is great. Slowpoke makes it better with:
|
4
4
|
|
5
|
-
- custom error
|
6
|
-
-
|
7
|
-
-
|
5
|
+
- custom error pages
|
6
|
+
- [safer service timeouts](https://github.com/heroku/rack-timeout/issues/39)
|
7
|
+
- wait timeouts that don’t kill your web server
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -22,47 +22,43 @@ rails generate slowpoke:install
|
|
22
22
|
|
23
23
|
This creates a `public/503.html` you can customize.
|
24
24
|
|
25
|
+
## How to Use
|
26
|
+
|
25
27
|
The default timeout is 15 seconds. Change this with:
|
26
28
|
|
27
29
|
```ruby
|
28
|
-
Slowpoke.timeout = 10
|
30
|
+
Slowpoke.timeout = 10
|
29
31
|
```
|
30
32
|
|
31
|
-
|
33
|
+
or set:
|
32
34
|
|
33
35
|
```ruby
|
34
|
-
|
35
|
-
# report timeout
|
36
|
-
end
|
36
|
+
ENV["REQUEST_TIMEOUT"]
|
37
37
|
```
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
Add this line to your application’s Gemfile:
|
39
|
+
Subscribe to timeouts with:
|
42
40
|
|
43
41
|
```ruby
|
44
|
-
|
42
|
+
ActiveSupport::Notifications.subscribe "timeout.slowpoke" do |name, start, finish, id, payload|
|
43
|
+
# report timeout
|
44
|
+
end
|
45
45
|
```
|
46
46
|
|
47
|
-
|
47
|
+
To learn more, see the [Rack::Timeout documentation](https://github.com/heroku/rack-timeout#the-rabbit-hole).
|
48
48
|
|
49
|
-
|
50
|
-
Slowpoke.timeout = proc{|env| env["REQUEST_PATH"].start_with?("/admin") ? 15 : 5 }
|
51
|
-
```
|
49
|
+
## Database Timeouts
|
52
50
|
|
53
|
-
|
51
|
+
For PostgreSQL, set a statement timeout in `config/database.yml`:
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
```yaml
|
54
|
+
production:
|
55
|
+
variables:
|
56
|
+
statement_timeout: 30000 # ms
|
59
57
|
```
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
## TODO
|
59
|
+
## Upgrading
|
64
60
|
|
65
|
-
|
61
|
+
`0.1.0` removes database timeouts, since Rails supports them by default.
|
66
62
|
|
67
63
|
## Contributing
|
68
64
|
|
data/lib/slowpoke.rb
CHANGED
@@ -2,7 +2,6 @@ require "slowpoke/version"
|
|
2
2
|
require "rack-timeout"
|
3
3
|
require "safely_block"
|
4
4
|
require "slowpoke/controller"
|
5
|
-
require "slowpoke/postgres"
|
6
5
|
require "slowpoke/railtie"
|
7
6
|
require "action_dispatch/middleware/exception_wrapper"
|
8
7
|
require "action_controller/base"
|
@@ -10,10 +9,6 @@ require "action_controller/base"
|
|
10
9
|
module Slowpoke
|
11
10
|
ENV_KEY = "slowpoke.timed_out".freeze
|
12
11
|
|
13
|
-
class << self
|
14
|
-
attr_writer :database_timeout
|
15
|
-
end
|
16
|
-
|
17
12
|
def self.timeout
|
18
13
|
@timeout ||= (ENV["REQUEST_TIMEOUT"] || ENV["TIMEOUT"] || 15).to_i
|
19
14
|
end
|
@@ -22,14 +17,11 @@ module Slowpoke
|
|
22
17
|
timeout = timeout.to_i if timeout.respond_to?(:to_i)
|
23
18
|
@timeout = Rack::Timeout.timeout = timeout
|
24
19
|
end
|
25
|
-
|
26
|
-
def self.database_timeout
|
27
|
-
@database_timeout ||= ENV["DATABASE_TIMEOUT"].to_i if ENV["DATABASE_TIMEOUT"]
|
28
|
-
end
|
29
20
|
end
|
30
21
|
|
31
22
|
# custom error page
|
32
23
|
ActionDispatch::ExceptionWrapper.rescue_responses["Rack::Timeout::RequestTimeoutError"] = :service_unavailable
|
24
|
+
ActionDispatch::ExceptionWrapper.rescue_responses["Rack::Timeout::RequestExpiryError"] = :service_unavailable
|
33
25
|
|
34
26
|
# remove noisy logger
|
35
27
|
Rack::Timeout.unregister_state_change_observer(:logger)
|
@@ -53,9 +45,3 @@ end
|
|
53
45
|
|
54
46
|
# bubble exceptions for error reporting libraries
|
55
47
|
ActionController::Base.send(:include, Slowpoke::Controller)
|
56
|
-
|
57
|
-
if defined?(PG)
|
58
|
-
require "active_record/connection_adapters/postgresql_adapter"
|
59
|
-
# database timeout
|
60
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, Slowpoke::Postgres)
|
61
|
-
end
|
data/lib/slowpoke/railtie.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module Slowpoke
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
initializer "slowpoke" do
|
3
|
+
initializer "slowpoke" do |app|
|
4
4
|
Rack::Timeout.timeout = Slowpoke.timeout
|
5
|
-
|
5
|
+
|
6
|
+
# prevent RequestExpiryError from killing web server
|
7
|
+
app.config.middleware.delete "Rack::Timeout"
|
8
|
+
app.config.middleware.insert_before "ActionDispatch::RemoteIp", "Rack::Timeout"
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
data/lib/slowpoke/version.rb
CHANGED
data/slowpoke.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slowpoke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rack-timeout
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +96,6 @@ files:
|
|
82
96
|
- lib/generators/slowpoke/templates/503.html
|
83
97
|
- lib/slowpoke.rb
|
84
98
|
- lib/slowpoke/controller.rb
|
85
|
-
- lib/slowpoke/postgres.rb
|
86
99
|
- lib/slowpoke/railtie.rb
|
87
100
|
- lib/slowpoke/version.rb
|
88
101
|
- slowpoke.gemspec
|
data/lib/slowpoke/postgres.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Slowpoke
|
2
|
-
module Postgres
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
alias_method_chain :configure_connection, :statement_timeout
|
7
|
-
end
|
8
|
-
|
9
|
-
def configure_connection_with_statement_timeout
|
10
|
-
configure_connection_without_statement_timeout
|
11
|
-
safely do
|
12
|
-
timeout = Slowpoke.database_timeout || Slowpoke.timeout
|
13
|
-
if timeout && !timeout.respond_to?(:call)
|
14
|
-
if ActiveRecord::Base.logger
|
15
|
-
ActiveRecord::Base.logger.silence do
|
16
|
-
execute("SET statement_timeout = #{timeout * 1000}")
|
17
|
-
end
|
18
|
-
else
|
19
|
-
execute("SET statement_timeout = #{timeout * 1000}")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|