slowpoke 0.1.0 → 0.1.1
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/CHANGELOG.md +4 -0
- data/README.md +39 -3
- data/lib/slowpoke.rb +3 -8
- data/lib/slowpoke/middleware.rb +23 -0
- data/lib/slowpoke/migration.rb +19 -0
- data/lib/slowpoke/railtie.rb +1 -0
- data/lib/slowpoke/version.rb +1 -1
- data/slowpoke.gemspec +2 -2
- metadata +7 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c5f0a6122b30b1ab9e451cb58a294368a13e9925
         | 
| 4 | 
            +
              data.tar.gz: 9970da3afc5dab294ebdd817c6b412faebbc6577
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bcd4a2ff4292b535615947f440cbef41037a0aaa4e61d9f8d478158875172f76c79dff4f4bbba3751cba7c1e674918e150053520aab52864fc45ece66a6bcb44
         | 
| 7 | 
            +
              data.tar.gz: cf6a6cf5030ce46c9a45dd661472865fd6af88844027ad2ab38c35e8988ad4fca4fd9d797e4bb545684a204cdd14782447b363748cc09b9c43e194485205b9a6
         | 
    
        data/CHANGELOG.md
    ADDED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -36,6 +36,12 @@ or set: | |
| 36 36 | 
             
            ENV["REQUEST_TIMEOUT"]
         | 
| 37 37 | 
             
            ```
         | 
| 38 38 |  | 
| 39 | 
            +
            Test by adding a `sleep` call to one of your actions:
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            ```ruby
         | 
| 42 | 
            +
            sleep(20)
         | 
| 43 | 
            +
            ```
         | 
| 44 | 
            +
             | 
| 39 45 | 
             
            Subscribe to timeouts with:
         | 
| 40 46 |  | 
| 41 47 | 
             
            ```ruby
         | 
| @@ -48,17 +54,47 @@ To learn more, see the [Rack::Timeout documentation](https://github.com/heroku/r | |
| 48 54 |  | 
| 49 55 | 
             
            ## Database Timeouts
         | 
| 50 56 |  | 
| 51 | 
            -
            For PostgreSQL, set  | 
| 57 | 
            +
            For PostgreSQL, set connect and statement timeouts in `config/database.yml`:
         | 
| 52 58 |  | 
| 53 59 | 
             
            ```yaml
         | 
| 54 60 | 
             
            production:
         | 
| 61 | 
            +
              connect_timeout: 1 # sec
         | 
| 55 62 | 
             
              variables:
         | 
| 56 | 
            -
                statement_timeout:  | 
| 63 | 
            +
                statement_timeout: 250 # ms
         | 
| 64 | 
            +
            ```
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            To use a different statement timeout for migrations, set:
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            ```ruby
         | 
| 69 | 
            +
            ENV["MIGRATION_STATEMENT_TIMEOUT"] = 60000 # ms
         | 
| 70 | 
            +
            ```
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            Test connect timeouts by setting your database host to an [unroutable IP](http://stackoverflow.com/questions/100841/artificially-create-a-connection-timeout-error).
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            ```yaml
         | 
| 75 | 
            +
            development:
         | 
| 76 | 
            +
              host: 10.255.255.1
         | 
| 77 | 
            +
            ```
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            Test statement timeouts with the [pg_sleep](http://www.postgresql.org/docs/9.0/static/functions-datetime.html#FUNCTIONS-DATETIME-DELAY) function.
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            ```sql
         | 
| 82 | 
            +
            SELECT pg_sleep(20);
         | 
| 57 83 | 
             
            ```
         | 
| 58 84 |  | 
| 59 85 | 
             
            ## Upgrading
         | 
| 60 86 |  | 
| 61 | 
            -
            `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 | 
            +
             | 
| 89 | 
            +
            ```yaml
         | 
| 90 | 
            +
            production:
         | 
| 91 | 
            +
              variables:
         | 
| 92 | 
            +
                statement_timeout: <%= Slowpoke.timeout * 1000 %>
         | 
| 93 | 
            +
            ```
         | 
| 94 | 
            +
             | 
| 95 | 
            +
            ## History
         | 
| 96 | 
            +
             | 
| 97 | 
            +
            View the [changelog](https://github.com/ankane/slowpoke/blob/master/CHANGELOG.md)
         | 
| 62 98 |  | 
| 63 99 | 
             
            ## Contributing
         | 
| 64 100 |  | 
    
        data/lib/slowpoke.rb
    CHANGED
    
    | @@ -2,6 +2,8 @@ require "slowpoke/version" | |
| 2 2 | 
             
            require "rack-timeout"
         | 
| 3 3 | 
             
            require "safely_block"
         | 
| 4 4 | 
             
            require "slowpoke/controller"
         | 
| 5 | 
            +
            require "slowpoke/middleware"
         | 
| 6 | 
            +
            require "slowpoke/migration"
         | 
| 5 7 | 
             
            require "slowpoke/railtie"
         | 
| 6 8 | 
             
            require "action_dispatch/middleware/exception_wrapper"
         | 
| 7 9 | 
             
            require "action_controller/base"
         | 
| @@ -28,18 +30,11 @@ Rack::Timeout.unregister_state_change_observer(:logger) | |
| 28 30 |  | 
| 29 31 | 
             
            # process protection and notifications
         | 
| 30 32 | 
             
            Rack::Timeout.register_state_change_observer(:slowpoke) do |env|
         | 
| 31 | 
            -
               | 
| 32 | 
            -
              when :timed_out
         | 
| 33 | 
            +
              if env[Rack::Timeout::ENV_INFO_KEY].state == :timed_out
         | 
| 33 34 | 
             
                env[Slowpoke::ENV_KEY] = true
         | 
| 34 35 |  | 
| 35 36 | 
             
                # TODO better payload
         | 
| 36 37 | 
             
                ActiveSupport::Notifications.instrument("timeout.slowpoke", {})
         | 
| 37 | 
            -
              when :completed
         | 
| 38 | 
            -
                # extremely important
         | 
| 39 | 
            -
                # protect the process with a restart
         | 
| 40 | 
            -
                # https://github.com/heroku/rack-timeout/issues/39
         | 
| 41 | 
            -
                # can't do in timed_out state consistently
         | 
| 42 | 
            -
                Process.kill("QUIT", Process.pid) if env[Slowpoke::ENV_KEY]
         | 
| 43 38 | 
             
              end
         | 
| 44 39 | 
             
            end
         | 
| 45 40 |  | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            module Slowpoke
         | 
| 2 | 
            +
              class Middleware
         | 
| 3 | 
            +
                def initialize(app)
         | 
| 4 | 
            +
                  @app = app
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def call(env)
         | 
| 8 | 
            +
                  response = @app.call(env)
         | 
| 9 | 
            +
                  if env[Slowpoke::ENV_KEY]
         | 
| 10 | 
            +
                    # extremely important
         | 
| 11 | 
            +
                    # protect the process with a restart
         | 
| 12 | 
            +
                    # https://github.com/heroku/rack-timeout/issues/39
         | 
| 13 | 
            +
                    # can't do in timed_out state consistently
         | 
| 14 | 
            +
                    if defined?(::PhusionPassenger)
         | 
| 15 | 
            +
                      `passenger-config detach-process #{Process.pid}`
         | 
| 16 | 
            +
                    else
         | 
| 17 | 
            +
                      Process.kill("QUIT", Process.pid)
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  response
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Slowpoke
         | 
| 2 | 
            +
              module Migration
         | 
| 3 | 
            +
                def connection
         | 
| 4 | 
            +
                  if ENV["MIGRATION_STATEMENT_TIMEOUT"]
         | 
| 5 | 
            +
                    @connection_with_timeout ||= begin
         | 
| 6 | 
            +
                      config = ActiveRecord::Base.connection_config
         | 
| 7 | 
            +
                      config["variables"] ||= {}
         | 
| 8 | 
            +
                      config["variables"]["statement_timeout"] = ENV["MIGRATION_STATEMENT_TIMEOUT"].to_i
         | 
| 9 | 
            +
                      ActiveRecord::Base.establish_connection(config)
         | 
| 10 | 
            +
                      ActiveRecord::Base.connection
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
                  else
         | 
| 13 | 
            +
                    super
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ActiveRecord::Migration.prepend(Slowpoke::Migration)
         | 
    
        data/lib/slowpoke/railtie.rb
    CHANGED
    
    | @@ -6,6 +6,7 @@ module Slowpoke | |
| 6 6 | 
             
                  # prevent RequestExpiryError from killing web server
         | 
| 7 7 | 
             
                  app.config.middleware.delete "Rack::Timeout"
         | 
| 8 8 | 
             
                  app.config.middleware.insert_before "ActionDispatch::RemoteIp", "Rack::Timeout"
         | 
| 9 | 
            +
                  app.config.middleware.insert 0, Slowpoke::Middleware
         | 
| 9 10 | 
             
                end
         | 
| 10 11 | 
             
              end
         | 
| 11 12 | 
             
            end
         | 
    
        data/lib/slowpoke/version.rb
    CHANGED
    
    
    
        data/slowpoke.gemspec
    CHANGED
    
    | @@ -8,8 +8,8 @@ Gem::Specification.new do |spec| | |
| 8 8 | 
             
              spec.version       = Slowpoke::VERSION
         | 
| 9 9 | 
             
              spec.authors       = ["Andrew Kane"]
         | 
| 10 10 | 
             
              spec.email         = ["andrew@chartkick.com"]
         | 
| 11 | 
            -
              spec.summary       = " | 
| 12 | 
            -
              spec.description   = " | 
| 11 | 
            +
              spec.summary       = "Rack::Timeout is great. Slowpoke makes it better."
         | 
| 12 | 
            +
              spec.description   = "Rack::Timeout is great. Slowpoke makes it better."
         | 
| 13 13 | 
             
              spec.homepage      = "https://github.com/ankane/slowpoke"
         | 
| 14 14 | 
             
              spec.license       = "MIT"
         | 
| 15 15 |  | 
    
        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.1. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 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-08-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| @@ -80,7 +80,7 @@ dependencies: | |
| 80 80 | 
             
                - - "~>"
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 82 | 
             
                    version: '10.0'
         | 
| 83 | 
            -
            description:  | 
| 83 | 
            +
            description: Rack::Timeout is great. Slowpoke makes it better.
         | 
| 84 84 | 
             
            email:
         | 
| 85 85 | 
             
            - andrew@chartkick.com
         | 
| 86 86 | 
             
            executables: []
         | 
| @@ -88,6 +88,7 @@ extensions: [] | |
| 88 88 | 
             
            extra_rdoc_files: []
         | 
| 89 89 | 
             
            files:
         | 
| 90 90 | 
             
            - ".gitignore"
         | 
| 91 | 
            +
            - CHANGELOG.md
         | 
| 91 92 | 
             
            - Gemfile
         | 
| 92 93 | 
             
            - LICENSE.txt
         | 
| 93 94 | 
             
            - README.md
         | 
| @@ -96,6 +97,8 @@ files: | |
| 96 97 | 
             
            - lib/generators/slowpoke/templates/503.html
         | 
| 97 98 | 
             
            - lib/slowpoke.rb
         | 
| 98 99 | 
             
            - lib/slowpoke/controller.rb
         | 
| 100 | 
            +
            - lib/slowpoke/middleware.rb
         | 
| 101 | 
            +
            - lib/slowpoke/migration.rb
         | 
| 99 102 | 
             
            - lib/slowpoke/railtie.rb
         | 
| 100 103 | 
             
            - lib/slowpoke/version.rb
         | 
| 101 104 | 
             
            - slowpoke.gemspec
         | 
| @@ -122,6 +125,6 @@ rubyforge_project: | |
| 122 125 | 
             
            rubygems_version: 2.4.5
         | 
| 123 126 | 
             
            signing_key: 
         | 
| 124 127 | 
             
            specification_version: 4
         | 
| 125 | 
            -
            summary:  | 
| 128 | 
            +
            summary: Rack::Timeout is great. Slowpoke makes it better.
         | 
| 126 129 | 
             
            test_files: []
         | 
| 127 130 | 
             
            has_rdoc: 
         |