resque-heroku-autoscaler 0.2.2 → 0.2.3

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.
data/GEMFILE CHANGED
@@ -6,7 +6,6 @@ gem 'heroku', '1.11.0'
6
6
  group :development do
7
7
  gem "rspec", "~> 2.0"
8
8
  gem 'rr', '1.0.2'
9
- gem 'echoe'
10
9
  gem 'rake'
11
10
  end
12
11
 
data/README.md CHANGED
@@ -54,6 +54,15 @@ Per default RHA will only start a single worker, no matter how many jobs are pen
54
54
 
55
55
  When calculating the new number of required workers the block given to new_worker_count will be called. Thus the example will result in starting one additional worker for every 5 pending jobs.
56
56
 
57
+ You might want to turn off scaling of your workers in development modus. You can do that by setting _scaling_disabled_ to true in your init script:
58
+
59
+ if (Rails.env == 'development')
60
+ Resque::Plugins::HerokuAutoscaler.config do |c|
61
+ c.scaling_disabled = true
62
+ end
63
+ end
64
+
65
+
57
66
 
58
67
  [dh]: http://blog.darkhax.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
59
68
  [rq]: http://github.com/defunkt/resque
@@ -4,6 +4,13 @@ module Resque
4
4
  module Config
5
5
  extend self
6
6
 
7
+ @scaling_disabled = false
8
+
9
+ attr_writer :scaling_disabled
10
+ def scaling_disabled?
11
+ @scaling_disabled
12
+ end
13
+
7
14
  @new_worker_count = Proc.new {|pending| pending >0 ? 1 : 0}
8
15
 
9
16
  attr_writer :heroku_user
@@ -28,6 +35,11 @@ module Resque
28
35
  @new_worker_count.call(pending, *payload)
29
36
  end
30
37
  end
38
+
39
+ def reset
40
+ @scaling_disabled = false
41
+ @new_worker_count = Proc.new {|pending| pending >0 ? 1 : 0}
42
+ end
31
43
  end
32
44
  end
33
45
  end
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module HerokuAutoscaler
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
6
6
  end
7
7
  end
@@ -39,8 +39,20 @@ module Resque
39
39
  private
40
40
 
41
41
  def calculate_and_set_workers
42
+ if Resque::Plugins::HerokuAutoscaler::Config.scaling_disabled?
43
+ log "Scaling workers disabled. Skipping."
44
+ return
45
+ end
42
46
  set_workers(Resque::Plugins::HerokuAutoscaler::Config.new_worker_count(Resque.info[:pending]))
43
47
  end
48
+
49
+ def log(message)
50
+ if defined?(Rails)
51
+ Rails.logger.info(message)
52
+ else
53
+ puts message
54
+ end
55
+ end
44
56
  end
45
57
  end
46
58
  end
@@ -43,6 +43,16 @@ describe Resque::Plugins::HerokuAutoscaler::Config do
43
43
  end
44
44
  end
45
45
 
46
+ describe ".scaling_disabled?" do
47
+
48
+ it{ Resque::Plugins::HerokuAutoscaler::Config.scaling_disabled?.should be_false}
49
+
50
+ it "sets scaling to disabled" do
51
+ subject.scaling_disabled = true
52
+ subject.scaling_disabled?.should be_true
53
+ end
54
+ end
55
+
46
56
  describe ".new_worker_count" do
47
57
  before do
48
58
  @original_method = Resque::Plugins::HerokuAutoscaler::Config.instance_variable_get(:@new_worker_count)
@@ -24,6 +24,8 @@ describe Resque::Plugins::HerokuAutoscaler do
24
24
  @fake_heroku_client = Object.new
25
25
  stub(@fake_heroku_client).set_workers
26
26
  stub(@fake_heroku_client).info { {:workers => 0} }
27
+ stub(TestJob).log
28
+ Resque::Plugins::HerokuAutoscaler::Config.reset
27
29
  end
28
30
 
29
31
  it "should be a valid Resque plugin" do
@@ -69,6 +71,19 @@ describe Resque::Plugins::HerokuAutoscaler do
69
71
  TestJob.after_enqueue_scale_workers_up
70
72
  end
71
73
  end
74
+
75
+ context "when scaling workers is disabled" do
76
+ before do
77
+ subject.config do |c|
78
+ c.scaling_disabled = true
79
+ end
80
+ end
81
+
82
+ it "should not use the heroku client" do
83
+ dont_allow(TestJob).heroku_client
84
+ TestJob.after_enqueue_scale_workers_up
85
+ end
86
+ end
72
87
  end
73
88
 
74
89
  describe ".after_perform_scale_workers_down" do
@@ -128,6 +143,19 @@ describe Resque::Plugins::HerokuAutoscaler do
128
143
  TestJob.after_perform_scale_workers_down
129
144
  end
130
145
  end
146
+
147
+ context "when scaling workers is disabled" do
148
+ before do
149
+ subject.config do |c|
150
+ c.scaling_disabled = true
151
+ end
152
+ end
153
+
154
+ it "should not use the heroku client" do
155
+ dont_allow(TestJob).heroku_client
156
+ TestJob.after_perform_scale_workers_down
157
+ end
158
+ end
131
159
  end
132
160
 
133
161
  describe ".on_failure_scale_workers" do
@@ -187,6 +215,19 @@ describe Resque::Plugins::HerokuAutoscaler do
187
215
  TestJob.on_failure_scale_workers
188
216
  end
189
217
  end
218
+
219
+ context "when scaling workers is disabled" do
220
+ before do
221
+ subject.config do |c|
222
+ c.scaling_disabled = true
223
+ end
224
+ end
225
+
226
+ it "should not use the heroku client" do
227
+ dont_allow(TestJob).heroku_client
228
+ TestJob.on_failure_scale_workers
229
+ end
230
+ end
190
231
  end
191
232
 
192
233
  describe ".set_workers" do
@@ -196,7 +237,7 @@ describe Resque::Plugins::HerokuAutoscaler do
196
237
  end
197
238
 
198
239
  stub(TestJob).current_workers {0}
199
- mock(TestJob).heroku_client { p "returning"; mock(@fake_heroku_client).set_workers('some_app_name', 10) }
240
+ mock(TestJob).heroku_client { mock(@fake_heroku_client).set_workers('some_app_name', 10) }
200
241
  TestJob.set_workers(10)
201
242
  end
202
243
  end
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
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-03-31 00:00:00 -07:00
18
+ date: 2011-04-16 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency