slowpoke 0.0.3 → 0.0.4

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: 536fd6527a9659642fa4aaad681b8eb617627db8
4
- data.tar.gz: 969103107e61959e4eda5efdc975ae7d478b3b9c
3
+ metadata.gz: 848181e682892057fb1b8a40498d2562833c54a1
4
+ data.tar.gz: 5ba28d18bf0779ab97772728f84a791e7c514733
5
5
  SHA512:
6
- metadata.gz: 8aa007b642cc348e14613c0baedfd774373fbf2ae4b81ab4ae4b48e335d30d42dbc82644bb4475e34ae2e051d8fd5a9c5e70ad6b7b0c9cac6078911178f6f20b
7
- data.tar.gz: 7c978167f493c0aef20ad9c3aaced4a0170480f2cb243da0257bf0c95569daf975bc39e0d64a73d752da7650432067a8316d4fff18405cced23bbb3b5dcdf55c
6
+ metadata.gz: df33f6fe3b6749485130421582cf3597e5a210c9284ff352c67698698d49196f848b2681ca946dda98bb9f624ef724474b4ee2cde64314b59d710c7afb975317
7
+ data.tar.gz: 6b4ae4e0ef05f9a600cfaa1e8c32186d1b803e624b42b870ad8f6d9e5abfc6ca4bfd41353c1741419590e04bef0640037b365e814f331677c591b1138e842425
data/README.md CHANGED
@@ -25,13 +25,7 @@ This creates a `public/503.html` you can customize.
25
25
  The default timeout is 15 seconds. Change this with:
26
26
 
27
27
  ```ruby
28
- Slowpoke.timeout = 10 # seconds
29
- ```
30
-
31
- or use:
32
-
33
- ```ruby
34
- ENV["TIMEOUT"] = 10
28
+ Slowpoke.timeout = 10 # or set ENV["REQUEST_TIMEOUT"]
35
29
  ```
36
30
 
37
31
  Subscribe to timeouts
@@ -42,14 +36,34 @@ ActiveSupport::Notifications.subscribe "timeout.slowpoke" do |name, start, finis
42
36
  end
43
37
  ```
44
38
 
39
+ ### Dynamic Timeouts
40
+
41
+ Add this line to your application’s Gemfile:
42
+
43
+ ```ruby
44
+ gem 'rack-timeout', github: 'ankane/rack-timeout'
45
+ ```
46
+
47
+ And use:
48
+
49
+ ```ruby
50
+ Slowpoke.timeout = proc{|env| env["REQUEST_PATH"].start_with?("/admin") ? 15 : 5 }
51
+ ```
52
+
45
53
  ### Database Timeouts
46
54
 
47
55
  For ActiveRecord (PostgreSQL only), change the database timeout with:
48
56
 
49
57
  ```ruby
50
- Slowpoke.database_timeout = 5
58
+ Slowpoke.database_timeout = 10 # or set ENV["DATABASE_TIMEOUT"]
51
59
  ```
52
60
 
61
+ Defaults to the request timeout (or no timeout if you use dynamic timeouts).
62
+
63
+ ## TODO
64
+
65
+ - block to bypass or change database timeout
66
+
53
67
  ## Contributing
54
68
 
55
69
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
@@ -2,17 +2,23 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>This page took too long to load (503)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
6
  <style>
6
7
  body {
7
8
  background-color: #EFEFEF;
8
9
  color: #2E2F30;
9
10
  text-align: center;
10
11
  font-family: arial, sans-serif;
12
+ margin: 0;
11
13
  }
12
14
 
13
15
  div.dialog {
14
- width: 25em;
15
- margin: 4em auto 0 auto;
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
16
22
  border: 1px solid #CCC;
17
23
  border-right-color: #999;
18
24
  border-left-color: #999;
@@ -21,7 +27,8 @@
21
27
  border-top-left-radius: 9px;
22
28
  border-top-right-radius: 9px;
23
29
  background-color: white;
24
- padding: 7px 4em 0 4em;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
25
32
  }
26
33
 
27
34
  h1 {
@@ -30,19 +37,19 @@
30
37
  line-height: 1.5em;
31
38
  }
32
39
 
33
- body > p {
34
- width: 33em;
35
- margin: 0 auto 1em;
36
- padding: 1em 0;
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
37
43
  background-color: #F7F7F7;
38
44
  border: 1px solid #CCC;
39
45
  border-right-color: #999;
46
+ border-left-color: #999;
40
47
  border-bottom-color: #999;
41
48
  border-bottom-left-radius: 4px;
42
49
  border-bottom-right-radius: 4px;
43
50
  border-top-color: #DADADA;
44
51
  color: #666;
45
- box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
46
53
  }
47
54
  </style>
48
55
  </head>
@@ -50,8 +57,10 @@
50
57
  <body>
51
58
  <!-- This file lives in public/503.html -->
52
59
  <div class="dialog">
53
- <h1>This page took too long to load.</h1>
60
+ <div>
61
+ <h1>This page took too long to load.</h1>
62
+ </div>
63
+ <p>Give it another shot.</p>
54
64
  </div>
55
- <p>Give it another shot.</p>
56
65
  </body>
57
66
  </html>
@@ -10,12 +10,14 @@ module Slowpoke
10
10
  configure_connection_without_statement_timeout
11
11
  safely do
12
12
  timeout = Slowpoke.database_timeout || Slowpoke.timeout
13
- if ActiveRecord::Base.logger
14
- ActiveRecord::Base.logger.silence do
13
+ if timeout and !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
15
19
  execute("SET statement_timeout = #{timeout * 1000}")
16
20
  end
17
- else
18
- execute("SET statement_timeout = #{timeout * 1000}")
19
21
  end
20
22
  end
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module Slowpoke
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/slowpoke.rb CHANGED
@@ -9,20 +9,25 @@ require "action_controller/base"
9
9
  require "active_record/connection_adapters/postgresql_adapter"
10
10
 
11
11
  module Slowpoke
12
- ENV_KEY = "slowpoke.timed_out"
12
+ ENV_KEY = "slowpoke.timed_out".freeze
13
13
 
14
14
  class << self
15
- attr_accessor :database_timeout
15
+ attr_writer :database_timeout
16
16
  end
17
17
 
18
18
  def self.timeout
19
- @timeout ||= (ENV["TIMEOUT"] || 15).to_i
19
+ @timeout ||= (ENV["REQUEST_TIMEOUT"] || ENV["TIMEOUT"] || 15).to_i
20
20
  end
21
21
 
22
22
  def self.timeout=(timeout)
23
- timeout = timeout.to_i if timeout
23
+ timeout = timeout.to_i if timeout.respond_to?(:to_i)
24
24
  @timeout = Rack::Timeout.timeout = timeout
25
25
  end
26
+
27
+ def self.database_timeout
28
+ @database_timeout ||= ENV["DATABASE_TIMEOUT"].to_i if ENV["DATABASE_TIMEOUT"]
29
+ end
30
+
26
31
  end
27
32
 
28
33
  # custom error page
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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-timeout