resque-heroku-autoscaler 0.2.1 → 0.2.2
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.
@@ -6,11 +6,15 @@ module Resque
|
|
6
6
|
@@heroku_client = nil
|
7
7
|
|
8
8
|
def after_enqueue_scale_workers_up(*args)
|
9
|
-
|
9
|
+
calculate_and_set_workers
|
10
10
|
end
|
11
11
|
|
12
12
|
def after_perform_scale_workers_down(*args)
|
13
|
-
|
13
|
+
calculate_and_set_workers
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_failure_scale_workers(*args)
|
17
|
+
calculate_and_set_workers
|
14
18
|
end
|
15
19
|
|
16
20
|
def set_workers(number_of_workers)
|
@@ -31,6 +35,12 @@ module Resque
|
|
31
35
|
def self.config
|
32
36
|
yield Resque::Plugins::HerokuAutoscaler::Config
|
33
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def calculate_and_set_workers
|
42
|
+
set_workers(Resque::Plugins::HerokuAutoscaler::Config.new_worker_count(Resque.info[:pending]))
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|
@@ -130,6 +130,65 @@ describe Resque::Plugins::HerokuAutoscaler do
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
+
describe ".on_failure_scale_workers" do
|
134
|
+
before do
|
135
|
+
stub(TestJob).heroku_client { @fake_heroku_client }
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should add the hook" do
|
139
|
+
Resque::Plugin.failure_hooks(TestJob).should include("on_failure_scale_workers")
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should take whatever args Resque hands in" do
|
143
|
+
Resque::Plugins::HerokuAutoscaler.class_eval("@@heroku_client = nil")
|
144
|
+
stub(Heroku::Client).new { stub!.set_workers }
|
145
|
+
|
146
|
+
lambda { TestJob.on_failure_scale_workers("some", "random", "aguments", 42) }.should_not raise_error
|
147
|
+
end
|
148
|
+
|
149
|
+
context "when the queue is empty" do
|
150
|
+
before do
|
151
|
+
stub(Resque).info { {:pending => 0} }
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should set workers to 0" do
|
155
|
+
mock(TestJob).set_workers(0)
|
156
|
+
TestJob.on_failure_scale_workers
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when the queue is not empty" do
|
161
|
+
before do
|
162
|
+
stub(Resque).info { {:pending => 1} }
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should keep workers at 1" do
|
166
|
+
mock(TestJob).set_workers(1)
|
167
|
+
TestJob.on_failure_scale_workers
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when new_worker_count was changed" do
|
172
|
+
before do
|
173
|
+
@original_method = Resque::Plugins::HerokuAutoscaler::Config.instance_variable_get(:@new_worker_count)
|
174
|
+
subject.config do |c|
|
175
|
+
c.new_worker_count do
|
176
|
+
2
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
after do
|
182
|
+
Resque::Plugins::HerokuAutoscaler::Config.instance_variable_set(:@new_worker_count, @original_method)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should use the given block" do
|
186
|
+
mock(TestJob).set_workers(2)
|
187
|
+
TestJob.on_failure_scale_workers
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
133
192
|
describe ".set_workers" do
|
134
193
|
it "should use the Heroku client to set the workers" do
|
135
194
|
subject.config do |c|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-heroku-autoscaler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Murmann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-31 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|