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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 386bc598cac17cf2094f6260750e204fae2f1eb3
4
- data.tar.gz: dbc8b84fbeb145cfc78ef211d033b7706a704287
3
+ metadata.gz: 29835ce4edb81b06635ee82405908c32d490623a
4
+ data.tar.gz: 8653542563bcee20f8c5288b327a2bc6337f707b
5
5
  SHA512:
6
- metadata.gz: e8f0ec80ef1ee5c638ca7cddc25fd0592da42920dbcb5c5daaefb6b0cfb8de9afae611f69795e76a394a13c994f58b7ea171fc6dd5e9f1398296885be9ae0655
7
- data.tar.gz: fcc475c88fcb9374ba26c1c7bd14bf132a378698300661d50709f0f3a2ace41a2ab94292f3098b8f31a6e4ad2fcc4500f6139c7e46451418d12bb03b03c52e03
6
+ metadata.gz: a24ee1b1e5f943bbc462a0f3ace64178f2a5ae9bf219fce257e4d97193e760179babc07bb80d79bddeca82343f68a0e2b158a9510dee91f22e943e67e7498024
7
+ data.tar.gz: bc81cadcc3aaa7b54bf549e84d79c1e773f91895b3a795f4fd69e3f34845753f24358204a22c625d720fdcb98f9db08b43a526d14d58d3c01e0f8c1554239498
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in slowpoke.gemspec
4
4
  gemspec
5
+
6
+ gem "makara", github: "taskrabbit/makara"
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Slowpoke
2
2
 
3
- Timeouts made easy
3
+ [Rack::Timeout](https://github.com/heroku/rack-timeout) is great. Slowpoke makes it better with:
4
4
 
5
- - custom error page
6
- - database timeouts
7
- - notifications
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 # or set ENV["REQUEST_TIMEOUT"]
30
+ Slowpoke.timeout = 10
29
31
  ```
30
32
 
31
- Subscribe to timeouts
33
+ or set:
32
34
 
33
35
  ```ruby
34
- ActiveSupport::Notifications.subscribe "timeout.slowpoke" do |name, start, finish, id, payload|
35
- # report timeout
36
- end
36
+ ENV["REQUEST_TIMEOUT"]
37
37
  ```
38
38
 
39
- ### Dynamic Timeouts
40
-
41
- Add this line to your application’s Gemfile:
39
+ Subscribe to timeouts with:
42
40
 
43
41
  ```ruby
44
- gem 'rack-timeout', github: 'ankane/rack-timeout'
42
+ ActiveSupport::Notifications.subscribe "timeout.slowpoke" do |name, start, finish, id, payload|
43
+ # report timeout
44
+ end
45
45
  ```
46
46
 
47
- And use:
47
+ To learn more, see the [Rack::Timeout documentation](https://github.com/heroku/rack-timeout#the-rabbit-hole).
48
48
 
49
- ```ruby
50
- Slowpoke.timeout = proc{|env| env["REQUEST_PATH"].start_with?("/admin") ? 15 : 5 }
51
- ```
49
+ ## Database Timeouts
52
50
 
53
- ### Database Timeouts
51
+ For PostgreSQL, set a statement timeout in `config/database.yml`:
54
52
 
55
- For ActiveRecord (PostgreSQL only), change the database timeout with:
56
-
57
- ```ruby
58
- Slowpoke.database_timeout = 10 # or set ENV["DATABASE_TIMEOUT"]
53
+ ```yaml
54
+ production:
55
+ variables:
56
+ statement_timeout: 30000 # ms
59
57
  ```
60
58
 
61
- Defaults to the request timeout (or no timeout if you use dynamic timeouts).
62
-
63
- ## TODO
59
+ ## Upgrading
64
60
 
65
- - block to bypass or change database timeout
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
@@ -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
- ActiveRecord::Base.logger.class.send(:include, ::LoggerSilence) if ActiveRecord::Base.logger
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
@@ -1,3 +1,3 @@
1
1
  module Slowpoke
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/slowpoke.gemspec CHANGED
@@ -18,6 +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 "rails"
21
22
  spec.add_dependency "rack-timeout", ">= 0.1.0"
22
23
  spec.add_dependency "safely_block"
23
24
 
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.6
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-03-16 00:00:00.000000000 Z
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
@@ -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