heroscale 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -5
- data/Rakefile +0 -1
- data/heroscale.gemspec +4 -3
- data/lib/heroscale/middleware.rb +29 -0
- data/lib/heroscale/railtie.rb +0 -0
- data/lib/heroscale.rb +2 -0
- data/spec/heroscale/middleware_spec.rb +74 -0
- data/spec/spec_helper.rb +8 -0
- metadata +33 -13
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
heroscale (0.0.
|
5
|
-
rack (~> 1.0)
|
4
|
+
heroscale (0.0.2)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: http://rubygems.org/
|
9
8
|
specs:
|
10
9
|
diff-lcs (1.1.2)
|
11
|
-
|
10
|
+
json (1.4.6)
|
12
11
|
rake (0.8.7)
|
13
12
|
rspec (2.1.0)
|
14
13
|
rspec-core (~> 2.1.0)
|
@@ -24,6 +23,6 @@ PLATFORMS
|
|
24
23
|
|
25
24
|
DEPENDENCIES
|
26
25
|
heroscale!
|
27
|
-
|
28
|
-
rake
|
26
|
+
json
|
27
|
+
rake (~> 0.8.7)
|
29
28
|
rspec (~> 2.0)
|
data/Rakefile
CHANGED
data/heroscale.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "heroscale"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
|
5
5
|
s.authors = ["Jacques Crocker"]
|
6
6
|
s.summary = "Autoscale your heroku app"
|
7
|
-
s.description = "
|
7
|
+
s.description = "Rack middleware that allows easy external querying of your heroku's app queue depth"
|
8
8
|
|
9
9
|
s.email = "railsjedi@gmail.com"
|
10
10
|
s.homepage = "http://github.com/railsjedi/heroscale"
|
@@ -27,8 +27,9 @@ Gem::Specification.new do |s|
|
|
27
27
|
"README.md"
|
28
28
|
]
|
29
29
|
|
30
|
-
s.
|
30
|
+
s.add_development_dependency "json"
|
31
31
|
s.add_development_dependency "rspec", "~> 2.0"
|
32
|
+
s.add_development_dependency 'rake', '~> 0.8.7'
|
32
33
|
end
|
33
34
|
|
34
35
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Heroscale
|
2
|
+
|
3
|
+
# simple Rack Middleware that adds a hook to return the heroku env info
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env["PATH_INFO"] == "/heroscale/status"
|
11
|
+
queue_wait_time = env['HTTP_X_HEROKU_QUEUE_WAIT_TIME']
|
12
|
+
queue_depth = env['HTTP_X_HEROKU_QUEUE_DEPTH']
|
13
|
+
dynos_in_use = env['HTTP_X_HEROKU_DYNOS_IN_USE']
|
14
|
+
|
15
|
+
if queue_wait_time and queue_depth and dynos_in_use
|
16
|
+
# format the response on heroku
|
17
|
+
res = %|{"heroku": true, "queue_wait_time": #{queue_wait_time.to_i}, "queue_depth": #{queue_depth.to_i}, "dynos_in_use": #{dynos_in_use.to_i}}|
|
18
|
+
else
|
19
|
+
res = %|{"heroku": false}|
|
20
|
+
end
|
21
|
+
|
22
|
+
[ 200, {'Content-Type' => 'application/json'}, res]
|
23
|
+
else
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
File without changes
|
data/lib/heroscale.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "heroscale"
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
describe Heroscale::Middleware do
|
7
|
+
|
8
|
+
# this is our original app (that the middleware is wrapping around)
|
9
|
+
let(:orig_app) do
|
10
|
+
lambda do |env|
|
11
|
+
[ 200, {'Content-Type' => 'application/json'}, "HELLO!"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# this is our app with the middleware attached
|
16
|
+
let(:app) do
|
17
|
+
Heroscale::Middleware.new orig_app
|
18
|
+
end
|
19
|
+
|
20
|
+
def heroku_request(opts = {})
|
21
|
+
app.call({
|
22
|
+
'PATH_INFO' => '/heroscale/status',
|
23
|
+
'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => (opts[:wait] || 100),
|
24
|
+
'HTTP_X_HEROKU_QUEUE_DEPTH' => (opts[:depth] || 0),
|
25
|
+
'HTTP_X_HEROKU_DYNOS_IN_USE' => (opts[:dynos] || 1)
|
26
|
+
})
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when querying on a heroku instance" do
|
30
|
+
before(:each) do
|
31
|
+
@rack_response = heroku_request(:wait => 100, :depth => 5, :dynos => 12)
|
32
|
+
@json = JSON.parse(@rack_response.last)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return the 'heroku' field that tells that we're on heroku" do
|
36
|
+
@json["heroku"].should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return the 'queue_wait_time' field that tells us the queue wait time" do
|
40
|
+
@json["queue_wait_time"].should == 100
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the 'queue_depth' field that tells us the current queue depth" do
|
44
|
+
@json["queue_depth"].should == 5
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return the 'dynos_in_use' field that tells us the current heroku dynos in use" do
|
48
|
+
@json["dynos_in_use"].should == 12
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when not quering the status link" do
|
54
|
+
it "should return the original app's response" do
|
55
|
+
app.call({}).last.should == "HELLO!"
|
56
|
+
app.call({"PATH_INFO" => "/"}).last.should == "HELLO!"
|
57
|
+
app.call({"PATH_INFO" => "/heroscale/"}).last.should == "HELLO!"
|
58
|
+
app.call({"PATH_INFO" => "/heroscale/status2"}).last.should == "HELLO!"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when query while not on a heroku instance" do
|
64
|
+
before(:each) do
|
65
|
+
@rack_response = app.call({"PATH_INFO" => "/heroscale/status"})
|
66
|
+
@json = JSON.parse(@rack_response.last)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return the 'heroku' field telling use we're not on heroku" do
|
70
|
+
@json["heroku"].should == false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jacques Crocker
|
@@ -14,21 +14,20 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-14 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: json
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
|
-
- 1
|
29
28
|
- 0
|
30
|
-
version: "
|
31
|
-
type: :
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
32
31
|
prerelease: false
|
33
32
|
version_requirements: *id001
|
34
33
|
- !ruby/object:Gem::Dependency
|
@@ -45,7 +44,22 @@ dependencies:
|
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
46
|
version_requirements: *id002
|
48
|
-
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
- 8
|
57
|
+
- 7
|
58
|
+
version: 0.8.7
|
59
|
+
type: :development
|
60
|
+
prerelease: false
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Rack middleware that allows easy external querying of your heroku's app queue depth
|
49
63
|
email: railsjedi@gmail.com
|
50
64
|
executables: []
|
51
65
|
|
@@ -55,6 +69,11 @@ extra_rdoc_files:
|
|
55
69
|
- LICENSE
|
56
70
|
- README.md
|
57
71
|
files:
|
72
|
+
- lib/heroscale/middleware.rb
|
73
|
+
- lib/heroscale/railtie.rb
|
74
|
+
- lib/heroscale.rb
|
75
|
+
- spec/heroscale/middleware_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
58
77
|
- heroscale.gemspec
|
59
78
|
- Gemfile
|
60
79
|
- Gemfile.lock
|
@@ -75,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
94
|
requirements:
|
76
95
|
- - ">="
|
77
96
|
- !ruby/object:Gem::Version
|
78
|
-
hash:
|
97
|
+
hash: -2259297854901398522
|
79
98
|
segments:
|
80
99
|
- 0
|
81
100
|
version: "0"
|
@@ -84,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
103
|
requirements:
|
85
104
|
- - ">="
|
86
105
|
- !ruby/object:Gem::Version
|
87
|
-
hash:
|
106
|
+
hash: -2259297854901398522
|
88
107
|
segments:
|
89
108
|
- 0
|
90
109
|
version: "0"
|
@@ -95,5 +114,6 @@ rubygems_version: 1.3.7
|
|
95
114
|
signing_key:
|
96
115
|
specification_version: 3
|
97
116
|
summary: Autoscale your heroku app
|
98
|
-
test_files:
|
99
|
-
|
117
|
+
test_files:
|
118
|
+
- spec/heroscale/middleware_spec.rb
|
119
|
+
- spec/spec_helper.rb
|