heroku_resque_autoscaler 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/README.md +17 -1
- data/heroku_resque_autoscaler.gemspec +2 -1
- data/lib/heroku_resque_autoscaler/configuration.rb +1 -9
- data/lib/heroku_resque_autoscaler/version.rb +1 -1
- data/spec/lib/heroku_resque_autoscaler/scaler_spec.rb +36 -11
- data/spec/spec_helper.rb +9 -1
- metadata +19 -9
- data/lib/heroku_resque_autoscaler/exceptions.rb +0 -3
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Inspired by [@darkhelmet](https://github.com/darkhelmet)'s
|
|
8
8
|
|
9
9
|
## Current Version
|
10
10
|
|
11
|
-
0.1.
|
11
|
+
0.1.1
|
12
12
|
|
13
13
|
|
14
14
|
## Requirements
|
@@ -94,6 +94,22 @@ rspec spec
|
|
94
94
|
```
|
95
95
|
|
96
96
|
|
97
|
+
## Coverage
|
98
|
+
|
99
|
+
```bash
|
100
|
+
rspec spec
|
101
|
+
open coverage/index.html
|
102
|
+
```
|
103
|
+
|
104
|
+
## Releases
|
105
|
+
|
106
|
+
```bash
|
107
|
+
vi lib/heroku_resque_autoscaler/version.rb # change version
|
108
|
+
vi README.md # change version
|
109
|
+
rake release
|
110
|
+
```
|
111
|
+
|
112
|
+
|
97
113
|
## License
|
98
114
|
|
99
115
|
Copyright (c) 2012 G5
|
@@ -17,7 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_dependency "heroku-api", "~> 0.3.5"
|
19
19
|
gem.add_dependency "resque", "~> 1.23.0"
|
20
|
-
|
20
|
+
|
21
|
+
gem.add_development_dependency "simplecov", "~> 0.7.1"
|
21
22
|
gem.add_development_dependency "rspec", "~> 2.11.0"
|
22
23
|
gem.add_development_dependency "guard-rspec", "~> 2.1.0"
|
23
24
|
gem.add_development_dependency "rb-fsevent", "~> 0.9.2"
|
@@ -35,18 +35,10 @@ module HerokuResqueAutoscaler
|
|
35
35
|
|
36
36
|
# Returns a hash of all configurable options merged with +hash+
|
37
37
|
#
|
38
|
-
# @param [Hash] hash A set of configuration options that will take
|
38
|
+
# @param [Hash] hash A set of configuration options that will take
|
39
39
|
# precedence over the defaults
|
40
40
|
def merge(hash)
|
41
41
|
to_hash.merge(hash)
|
42
42
|
end
|
43
|
-
|
44
|
-
def validate_presence(options)
|
45
|
-
OPTIONS.each_pair do |key, value|
|
46
|
-
if options[key].nil?
|
47
|
-
raise HerokuResqueAutoscaler::ConfigurationException, "#{key} is missing"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
43
|
end
|
52
44
|
end
|
@@ -12,11 +12,28 @@ describe HerokuResqueAutoscaler do
|
|
12
12
|
before :each do
|
13
13
|
@heroku = mock(Heroku::API)
|
14
14
|
HerokuResqueAutoscaler::Scaler.stub(:heroku).and_return(@heroku)
|
15
|
+
|
16
|
+
HerokuResqueAutoscaler.configure do |config|
|
17
|
+
config.heroku_api_key = "api-key"
|
18
|
+
config.heroku_app_name = "app-name"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:heroku_app_name) { "app-name" }
|
23
|
+
|
24
|
+
context ".api_key" do
|
25
|
+
it "returns api key" do
|
26
|
+
HerokuResqueAutoscaler::Scaler.api_key.should == "api-key"
|
27
|
+
end
|
15
28
|
end
|
16
29
|
|
17
|
-
|
30
|
+
context ".app_name" do
|
31
|
+
it "returns app name" do
|
32
|
+
HerokuResqueAutoscaler::Scaler.app_name.should == "app-name"
|
33
|
+
end
|
34
|
+
end
|
18
35
|
|
19
|
-
context "
|
36
|
+
context ".workers" do
|
20
37
|
it "returns the number of workers from the Heroku application" do
|
21
38
|
Excon.stub(method: :get) do |params|
|
22
39
|
{ status: 200,
|
@@ -29,20 +46,20 @@ describe HerokuResqueAutoscaler do
|
|
29
46
|
end
|
30
47
|
connection = Excon.new("http://example.com", mock: true)
|
31
48
|
response = connection.request(method: :get)
|
32
|
-
@heroku.should_receive(:get_ps).with(
|
49
|
+
@heroku.should_receive(:get_ps).with(heroku_app_name).and_return(response)
|
33
50
|
HerokuResqueAutoscaler::Scaler.workers.should == 2
|
34
51
|
end
|
35
52
|
end
|
36
53
|
|
37
|
-
context "
|
54
|
+
context ".workers=" do
|
38
55
|
it "sets the number of workers on Heroku to some quantity" do
|
39
56
|
quantity = 10
|
40
|
-
@heroku.should_receive(:post_ps_scale).with(
|
57
|
+
@heroku.should_receive(:post_ps_scale).with(heroku_app_name, :worker, quantity)
|
41
58
|
HerokuResqueAutoscaler::Scaler.workers = quantity
|
42
59
|
end
|
43
60
|
end
|
44
61
|
|
45
|
-
context "
|
62
|
+
context ".job_count" do
|
46
63
|
it "returns the Resque job count" do
|
47
64
|
num_pending = 10
|
48
65
|
Resque.should_receive(:info).and_return({:pending => num_pending})
|
@@ -50,11 +67,19 @@ describe HerokuResqueAutoscaler do
|
|
50
67
|
end
|
51
68
|
end
|
52
69
|
|
53
|
-
context "
|
70
|
+
context ".working_job_count" do
|
71
|
+
it "returns the Resque working job count" do
|
72
|
+
num_working = 10
|
73
|
+
Resque.should_receive(:info).and_return({:working => num_working})
|
74
|
+
HerokuResqueAutoscaler::Scaler.working_job_count.should == num_working
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context ".num_desired_heroku_workers" do
|
54
79
|
it "returns the number of workers we should have (1 worker per x jobs)" do
|
55
80
|
num_jobs = 100
|
56
81
|
HerokuResqueAutoscaler::Scaler.stub(:job_count).and_return(num_jobs)
|
57
|
-
HerokuResqueAutoscalerTestClass.num_desired_heroku_workers.should == 5
|
82
|
+
HerokuResqueAutoscalerTestClass.num_desired_heroku_workers.should == 5
|
58
83
|
|
59
84
|
num_jobs = 38
|
60
85
|
HerokuResqueAutoscaler::Scaler.unstub(:job_count)
|
@@ -64,7 +89,7 @@ describe HerokuResqueAutoscaler do
|
|
64
89
|
num_jobs = 1
|
65
90
|
HerokuResqueAutoscaler::Scaler.unstub(:job_count)
|
66
91
|
HerokuResqueAutoscaler::Scaler.stub(:job_count).and_return(num_jobs)
|
67
|
-
HerokuResqueAutoscalerTestClass.num_desired_heroku_workers.should == 1
|
92
|
+
HerokuResqueAutoscalerTestClass.num_desired_heroku_workers.should == 1
|
68
93
|
|
69
94
|
num_jobs = 10000
|
70
95
|
HerokuResqueAutoscaler::Scaler.unstub(:job_count)
|
@@ -73,7 +98,7 @@ describe HerokuResqueAutoscaler do
|
|
73
98
|
end
|
74
99
|
end
|
75
100
|
|
76
|
-
context "
|
101
|
+
context ".after_perform_scale_down" do
|
77
102
|
it "scales down the workers to zero if there are no jobs pending" do
|
78
103
|
HerokuResqueAutoscaler::Scaler.stub(:job_count).and_return(0)
|
79
104
|
HerokuResqueAutoscaler::Scaler.stub(:workers).and_return(1)
|
@@ -89,7 +114,7 @@ describe HerokuResqueAutoscaler do
|
|
89
114
|
end
|
90
115
|
end
|
91
116
|
|
92
|
-
context "
|
117
|
+
context ".after_enqueue_scale_up" do
|
93
118
|
it "ups the amount of workers if there are not enough" do
|
94
119
|
num_workers = 5
|
95
120
|
num_desired_workers = 6
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku_resque_autoscaler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: heroku-api
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 1.23.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: simplecov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.7.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.1
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rspec
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +132,7 @@ extensions: []
|
|
116
132
|
extra_rdoc_files: []
|
117
133
|
files:
|
118
134
|
- .gitignore
|
135
|
+
- .rspec
|
119
136
|
- Gemfile
|
120
137
|
- LICENSE
|
121
138
|
- README.md
|
@@ -123,7 +140,6 @@ files:
|
|
123
140
|
- heroku_resque_autoscaler.gemspec
|
124
141
|
- lib/heroku_resque_autoscaler.rb
|
125
142
|
- lib/heroku_resque_autoscaler/configuration.rb
|
126
|
-
- lib/heroku_resque_autoscaler/exceptions.rb
|
127
143
|
- lib/heroku_resque_autoscaler/scaler.rb
|
128
144
|
- lib/heroku_resque_autoscaler/version.rb
|
129
145
|
- spec/lib/heroku_resque_autoscaler/configuration_spec.rb
|
@@ -142,18 +158,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
158
|
- - ! '>='
|
143
159
|
- !ruby/object:Gem::Version
|
144
160
|
version: '0'
|
145
|
-
segments:
|
146
|
-
- 0
|
147
|
-
hash: -1170907037778639333
|
148
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
162
|
none: false
|
150
163
|
requirements:
|
151
164
|
- - ! '>='
|
152
165
|
- !ruby/object:Gem::Version
|
153
166
|
version: '0'
|
154
|
-
segments:
|
155
|
-
- 0
|
156
|
-
hash: -1170907037778639333
|
157
167
|
requirements: []
|
158
168
|
rubyforge_project:
|
159
169
|
rubygems_version: 1.8.24
|