slowpoke 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +1 -1
- data/README.md +30 -30
- data/lib/slowpoke.rb +0 -14
- data/lib/slowpoke/middleware.rb +2 -0
- data/lib/slowpoke/railtie.rb +9 -6
- data/lib/slowpoke/version.rb +1 -1
- metadata +10 -23
- data/.gitignore +0 -14
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/lib/slowpoke/migration.rb +0 -16
- data/slowpoke.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 196837a764b30dcd76bd206904b4f019a3dc77149a9ab472c9aaa062f5e00584
|
4
|
+
data.tar.gz: 410bd79283dc9921762ca886d54978f2adac2496e2ad0c6e8a381157e5318dc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46f0c622df519a853f40660bcdaa644e1e3586eeb8607ffd09420456a4b10d4a7b536154eb8b911d5131b9d8dca6afe0b6521f48191438176a7924cf6dec3b3d
|
7
|
+
data.tar.gz: 8ab0b75f01bd8f0662ba21ca4f130ff6926e2f5f5f11dedb296aec35ad2f06f957067d68c4defdf52774da5cdb756a2f590261b28193498ecb1128067ac34843
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# Slowpoke
|
2
2
|
|
3
|
-
[Rack::Timeout](https://github.com/heroku/rack-timeout)
|
3
|
+
[Rack::Timeout](https://github.com/heroku/rack-timeout) enhancements for Rails
|
4
4
|
|
5
5
|
- custom error pages
|
6
6
|
- [safer service timeouts](https://github.com/heroku/rack-timeout/issues/39)
|
7
|
-
- wait timeouts that don’t kill your web server
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
@@ -22,24 +21,29 @@ rails generate slowpoke:install
|
|
22
21
|
|
23
22
|
This creates a `public/503.html` you can customize.
|
24
23
|
|
25
|
-
##
|
24
|
+
## Trying It in Development
|
26
25
|
|
27
|
-
|
26
|
+
Temporarily add to `config/environments/development.rb`:
|
28
27
|
|
29
28
|
```ruby
|
30
|
-
|
29
|
+
config.slowpoke.timeout = 1
|
30
|
+
config.consider_all_requests_local = false
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
And add a `sleep` call to one of your actions:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
|
36
|
+
sleep(2)
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
The custom error page should appear.
|
40
|
+
|
41
|
+
## Configuring It for Production
|
42
|
+
|
43
|
+
The default timeout is 15 seconds. You can change this in `config/environments/production.rb` with:
|
40
44
|
|
41
45
|
```ruby
|
42
|
-
|
46
|
+
config.slowpoke.timeout = 5
|
43
47
|
```
|
44
48
|
|
45
49
|
Subscribe to timeouts with:
|
@@ -50,41 +54,37 @@ ActiveSupport::Notifications.subscribe "timeout.slowpoke" do |name, start, finis
|
|
50
54
|
end
|
51
55
|
```
|
52
56
|
|
53
|
-
To learn more, see the [Rack::Timeout documentation](https://github.com/heroku/rack-timeout
|
57
|
+
To learn more, see the [Rack::Timeout documentation](https://github.com/heroku/rack-timeout).
|
58
|
+
|
59
|
+
## Threaded Servers
|
60
|
+
|
61
|
+
The only safe way to recover from a request timeout is to spawn a new process. For threaded servers like Puma, this means killing all threads when any one of them times out. This can have a significant impact on performance.
|
54
62
|
|
55
63
|
## Database Timeouts
|
56
64
|
|
57
|
-
|
65
|
+
It’s a good idea to set a [statement timeout](https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts/#statement-timeouts-1) and a [connect timeout](https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts/#activerecord).
|
58
66
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
variables:
|
63
|
-
statement_timeout: 250 # ms
|
64
|
-
```
|
67
|
+
## Upgrading
|
68
|
+
|
69
|
+
### 0.3.0
|
65
70
|
|
66
|
-
|
71
|
+
If you set the timeout with:
|
67
72
|
|
68
73
|
```ruby
|
69
|
-
|
74
|
+
Slowpoke.timeout = 5
|
70
75
|
```
|
71
76
|
|
72
|
-
|
77
|
+
Remove it and add to `config/environments/production.rb`:
|
73
78
|
|
74
|
-
```
|
75
|
-
|
76
|
-
host: 10.255.255.1
|
79
|
+
```ruby
|
80
|
+
config.slowpoke.timeout = 5
|
77
81
|
```
|
78
82
|
|
79
|
-
|
83
|
+
If you use migration timeouts, check out [this guide](https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts/#statement-timeouts-1) for how to configure them directly in `config/database.yml`.
|
80
84
|
|
81
|
-
|
82
|
-
SELECT pg_sleep(20);
|
83
|
-
```
|
84
|
-
|
85
|
-
## Upgrading
|
85
|
+
### 0.1.0
|
86
86
|
|
87
|
-
`0.1.0` removes database timeouts, since Rails supports them by default.
|
87
|
+
`0.1.0` removes database timeouts, since Rails supports them by default. To restore the previous behavior, use:
|
88
88
|
|
89
89
|
```yaml
|
90
90
|
production:
|
data/lib/slowpoke.rb
CHANGED
@@ -1,26 +1,12 @@
|
|
1
1
|
require "slowpoke/version"
|
2
2
|
require "rack/timeout/base"
|
3
3
|
require "slowpoke/middleware"
|
4
|
-
require "slowpoke/migration"
|
5
4
|
require "slowpoke/railtie"
|
6
5
|
require "action_dispatch/middleware/exception_wrapper"
|
7
6
|
require "action_controller/base"
|
8
7
|
|
9
8
|
module Slowpoke
|
10
9
|
ENV_KEY = "slowpoke.timed_out".freeze
|
11
|
-
|
12
|
-
def self.timeout
|
13
|
-
@timeout ||= (ENV["REQUEST_TIMEOUT"] || ENV["TIMEOUT"] || 15).to_i
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.timeout=(timeout)
|
17
|
-
timeout = timeout.to_i if timeout.respond_to?(:to_i)
|
18
|
-
@timeout = Rack::Timeout.service_timeout = timeout
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.migration_statement_timeout
|
22
|
-
ENV["MIGRATION_STATEMENT_TIMEOUT"]
|
23
|
-
end
|
24
10
|
end
|
25
11
|
|
26
12
|
# custom error page
|
data/lib/slowpoke/middleware.rb
CHANGED
@@ -14,6 +14,8 @@ module Slowpoke
|
|
14
14
|
# can't do in timed_out state consistently
|
15
15
|
if defined?(::PhusionPassenger)
|
16
16
|
`passenger-config detach-process #{Process.pid}`
|
17
|
+
elsif defined?(::Puma)
|
18
|
+
Process.kill("TERM", Process.pid)
|
17
19
|
else
|
18
20
|
Process.kill("QUIT", Process.pid)
|
19
21
|
end
|
data/lib/slowpoke/railtie.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Slowpoke
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
+
config.slowpoke = ActiveSupport::OrderedOptions.new
|
4
|
+
|
3
5
|
initializer "slowpoke" do |app|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
service_timeout = app.config.slowpoke.timeout
|
7
|
+
service_timeout ||= ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] || ENV["REQUEST_TIMEOUT"] || ENV["TIMEOUT"] || 15
|
8
|
+
service_timeout = service_timeout.to_i
|
9
|
+
|
10
|
+
app.config.middleware.insert_after ActionDispatch::DebugExceptions, Rack::Timeout,
|
11
|
+
service_timeout: service_timeout
|
12
|
+
|
10
13
|
app.config.middleware.insert(0, Slowpoke::Middleware) unless Rails.env.development? || Rails.env.test?
|
11
14
|
end
|
12
15
|
end
|
data/lib/slowpoke/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slowpoke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2019-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5'
|
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: '
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,20 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
48
|
-
- - "<"
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.5.0
|
47
|
+
version: 0.4.0
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - ">="
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.
|
58
|
-
- - "<"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.5.0
|
54
|
+
version: 0.4.0
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: bundler
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,26 +81,20 @@ dependencies:
|
|
87
81
|
- !ruby/object:Gem::Version
|
88
82
|
version: '0'
|
89
83
|
description:
|
90
|
-
email:
|
91
|
-
- andrew@chartkick.com
|
84
|
+
email: andrew@chartkick.com
|
92
85
|
executables: []
|
93
86
|
extensions: []
|
94
87
|
extra_rdoc_files: []
|
95
88
|
files:
|
96
|
-
- ".gitignore"
|
97
89
|
- CHANGELOG.md
|
98
|
-
- Gemfile
|
99
90
|
- LICENSE.txt
|
100
91
|
- README.md
|
101
|
-
- Rakefile
|
102
92
|
- lib/generators/slowpoke/install_generator.rb
|
103
93
|
- lib/generators/slowpoke/templates/503.html
|
104
94
|
- lib/slowpoke.rb
|
105
95
|
- lib/slowpoke/middleware.rb
|
106
|
-
- lib/slowpoke/migration.rb
|
107
96
|
- lib/slowpoke/railtie.rb
|
108
97
|
- lib/slowpoke/version.rb
|
109
|
-
- slowpoke.gemspec
|
110
98
|
homepage: https://github.com/ankane/slowpoke
|
111
99
|
licenses:
|
112
100
|
- MIT
|
@@ -119,16 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
107
|
requirements:
|
120
108
|
- - ">="
|
121
109
|
- !ruby/object:Gem::Version
|
122
|
-
version: '
|
110
|
+
version: '2.4'
|
123
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
112
|
requirements:
|
125
113
|
- - ">="
|
126
114
|
- !ruby/object:Gem::Version
|
127
115
|
version: '0'
|
128
116
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.7.6
|
117
|
+
rubygems_version: 3.0.3
|
131
118
|
signing_key:
|
132
119
|
specification_version: 4
|
133
|
-
summary: Rack::Timeout
|
120
|
+
summary: Rack::Timeout enhancements for Rails
|
134
121
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/lib/slowpoke/migration.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Slowpoke
|
2
|
-
module Migration
|
3
|
-
def connection
|
4
|
-
connection = super
|
5
|
-
if Slowpoke.migration_statement_timeout && !@migration_statement_timeout_set
|
6
|
-
connection.execute("SET statement_timeout = #{Slowpoke.migration_statement_timeout.to_i}")
|
7
|
-
@migration_statement_timeout_set = true
|
8
|
-
end
|
9
|
-
connection
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
ActiveSupport.on_load(:active_record) do
|
15
|
-
ActiveRecord::Migration.prepend(Slowpoke::Migration)
|
16
|
-
end
|
data/slowpoke.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "slowpoke/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "slowpoke"
|
8
|
-
spec.version = Slowpoke::VERSION
|
9
|
-
spec.authors = ["Andrew Kane"]
|
10
|
-
spec.email = ["andrew@chartkick.com"]
|
11
|
-
spec.summary = "Rack::Timeout is great. Slowpoke makes it better."
|
12
|
-
spec.homepage = "https://github.com/ankane/slowpoke"
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_dependency "railties"
|
21
|
-
spec.add_dependency "actionpack"
|
22
|
-
spec.add_dependency "rack-timeout", ">= 0.3.0", "< 0.5.0"
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
end
|