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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b602f89b54077d5e970bb549ce1ad3e57db8d1ab6f15bf62ea3dbae868d6ca5
4
- data.tar.gz: 60cb3a0c463ebadeb4abec48794ffaa2b33b22af406c672ba2ac351f7134fbed
3
+ metadata.gz: 196837a764b30dcd76bd206904b4f019a3dc77149a9ab472c9aaa062f5e00584
4
+ data.tar.gz: 410bd79283dc9921762ca886d54978f2adac2496e2ad0c6e8a381157e5318dc2
5
5
  SHA512:
6
- metadata.gz: 94352be6969f60055f4f6121f9b087fb5a4b2e144014b973fe6aa772cb7c4c9bd4cc5922a51dc3a41ce9a70bcd97f5f1bd0516ec764d002e410a0578cf1ffb25
7
- data.tar.gz: bf7c814b78e54a679798107f013083a596fab63fab960734fa5d32ba689e35128b33da7430aa560f789c56d3982d6e58f226f960828e985828793db11549e404
6
+ metadata.gz: 46f0c622df519a853f40660bcdaa644e1e3586eeb8607ffd09420456a4b10d4a7b536154eb8b911d5131b9d8dca6afe0b6521f48191438176a7924cf6dec3b3d
7
+ data.tar.gz: 8ab0b75f01bd8f0662ba21ca4f130ff6926e2f5f5f11dedb296aec35ad2f06f957067d68c4defdf52774da5cdb756a2f590261b28193498ecb1128067ac34843
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.3.0
2
+
3
+ - Use proper signal for Puma
4
+ - Dropped support for rack-timeout < 0.4
5
+ - Dropped support for migration timeouts
6
+ - Dropped support for Rails < 5
7
+
1
8
  ## 0.2.1
2
9
 
3
10
  - Don’t kill server in test environment
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Andrew Kane
1
+ Copyright (c) 2014-2019 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Slowpoke
2
2
 
3
- [Rack::Timeout](https://github.com/heroku/rack-timeout) is great. Slowpoke makes it better with:
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
- ## How to Use
24
+ ## Trying It in Development
26
25
 
27
- The default timeout is 15 seconds. Change this with:
26
+ Temporarily add to `config/environments/development.rb`:
28
27
 
29
28
  ```ruby
30
- Slowpoke.timeout = 10
29
+ config.slowpoke.timeout = 1
30
+ config.consider_all_requests_local = false
31
31
  ```
32
32
 
33
- or set:
33
+ And add a `sleep` call to one of your actions:
34
34
 
35
35
  ```ruby
36
- ENV["REQUEST_TIMEOUT"]
36
+ sleep(2)
37
37
  ```
38
38
 
39
- Test by adding a `sleep` call to one of your actions:
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
- sleep(20)
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#the-rabbit-hole).
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
- For PostgreSQL, set connect and statement timeouts in `config/database.yml`:
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
- ```yaml
60
- production:
61
- connect_timeout: 1 # sec
62
- variables:
63
- statement_timeout: 250 # ms
64
- ```
67
+ ## Upgrading
68
+
69
+ ### 0.3.0
65
70
 
66
- To use a different statement timeout for migrations, set:
71
+ If you set the timeout with:
67
72
 
68
73
  ```ruby
69
- ENV["MIGRATION_STATEMENT_TIMEOUT"] = 60000 # ms
74
+ Slowpoke.timeout = 5
70
75
  ```
71
76
 
72
- Test connect timeouts by setting your database host to an [unroutable IP](https://stackoverflow.com/questions/100841/artificially-create-a-connection-timeout-error).
77
+ Remove it and add to `config/environments/production.rb`:
73
78
 
74
- ```yaml
75
- development:
76
- host: 10.255.255.1
79
+ ```ruby
80
+ config.slowpoke.timeout = 5
77
81
  ```
78
82
 
79
- Test statement timeouts with the [pg_sleep](https://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-DELAY) function.
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
- ```sql
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. To restore the previous behavior, use:
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
@@ -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
@@ -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
- Rack::Timeout.service_timeout = Slowpoke.timeout
5
- if Rails::VERSION::MAJOR >= 5
6
- app.config.middleware.insert_after ActionDispatch::DebugExceptions, Rack::Timeout
7
- else
8
- app.config.middleware.insert_before ActionDispatch::RemoteIp, Rack::Timeout
9
- end
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
@@ -1,3 +1,3 @@
1
1
  module Slowpoke
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.1
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: 2018-05-21 00:00:00.000000000 Z
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: '0'
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: '0'
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.3.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.3.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: '0'
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
- rubyforge_project:
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 is great. Slowpoke makes it better.
120
+ summary: Rack::Timeout enhancements for Rails
134
121
  test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in slowpoke.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -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