heroku-qc-autoscale 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -26,9 +26,10 @@ Create config/initializers/qc_autoscale.rb
26
26
  c.api_key = ENV['HEROKU_API_KEY']
27
27
  c.app = ENV['HEROKU_APP']
28
28
  c.scale = [1, 15, 30, 40, 50]
29
- c.active = Rails.env.production?
30
29
  end
31
30
 
31
+ Autoscale.activate! if Rails.env.production?
32
+
32
33
  Queue jobs as normal with QueueClassic. Based on your scale table, it will recalculate the
33
34
  workers required after each QC#enqueue, and QC#delete.
34
35
 
@@ -8,7 +8,7 @@ module Autoscale
8
8
  end
9
9
 
10
10
  def workers=(qty)
11
- client.put_workers(app, qty)
11
+ client.post_ps_scale(app, "worker", qty)
12
12
  end
13
13
 
14
14
  def job_count
@@ -1,7 +1,7 @@
1
1
  module Heroku
2
2
  module QC
3
3
  module Autoscale
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
@@ -9,16 +9,15 @@ require "autoscale/queue_classic/callbacks"
9
9
  require "heroku-qc-autoscale/version"
10
10
 
11
11
  module Autoscale
12
- mattr_accessor :api_key, :app, :mock, :scale, :active
12
+ mattr_accessor :api_key, :app, :mock, :scale
13
13
 
14
14
  # config and activate QC bindings
15
15
  def self.config(&block)
16
16
  yield(self)
17
- activate if active == true
18
17
  end
19
18
 
20
19
  # activate QC queue callbacks
21
- def self.activate
20
+ def self.activate!
22
21
  QC::Queue.send(:include, Autoscale::QueueClassic::QueueCallbacks)
23
22
  end
24
23
  end
@@ -1,69 +1,76 @@
1
1
  require_relative "../test_helper"
2
2
 
3
+ # mock class
4
+ class Autoscale::Heroku
5
+ def self.workers
6
+ @@workers ||= 0
7
+ end
8
+
9
+ def self.workers=(qty)
10
+ @@workers = qty
11
+ end
12
+ end
13
+
14
+ # stub heroku api call to scale
15
+ Excon.stub(:expects => 200, :method => :post, :path => %r{^/apps/([^/]+)/ps/scale}) do |params|
16
+ {body: params[:query][:qty], status: 200 }
17
+ end
18
+
3
19
  describe Autoscale::Heroku do
4
20
  include QCHelper
5
21
 
6
22
  subject { Autoscale::Heroku }
23
+ before { subject.workers = 0 }
7
24
 
8
25
  it "job_count should be 0" do
9
26
  subject.job_count.must_equal(0)
10
27
  end
11
28
 
12
29
  it "#workers" do
13
- with_app do |app|
14
- subject.workers = 1
15
- subject.workers.must_equal(1)
30
+ subject.workers = 1
31
+ subject.workers.must_equal(1)
16
32
 
17
- subject.workers = 2
18
- subject.workers.must_equal(2)
19
- end
33
+ subject.workers = 2
34
+ subject.workers.must_equal(2)
20
35
  end
21
36
 
22
37
  describe "scaling up" do
23
38
  it "with 5 jobs" do
24
- with_app do |app|
25
- 5.times{ QC.enqueue("Time.now") }
26
- subject.workers.must_equal(1)
27
- end
39
+ 5.times{ QC.enqueue("Time.now") }
40
+ subject.job_count.must_equal(5)
41
+ subject.workers.must_equal(1)
28
42
  end
29
43
 
30
44
  it "with 16 jobs" do
31
- with_app do |app|
32
- 16.times{ QC.enqueue("Time.now") }
33
- subject.workers.must_equal(2)
34
- end
45
+ 16.times{ QC.enqueue("Time.now") }
46
+ subject.job_count.must_equal(16)
47
+ subject.workers.must_equal(2)
35
48
  end
36
49
 
37
50
  it "with 31 jobs" do
38
- with_app do |app|
39
- 31.times{ QC.enqueue("Time.now") }
40
- subject.workers.must_equal(3)
41
- end
51
+ 31.times{ QC.enqueue("Time.now") }
52
+ subject.job_count.must_equal(31)
53
+ subject.workers.must_equal(3)
42
54
  end
43
55
 
44
56
  it "with 131 jobs" do
45
- with_app do |app|
46
- 131.times{ QC.enqueue("Time.now") }
47
- subject.workers.must_equal(5)
48
- end
57
+ 131.times{ QC.enqueue("Time.now") }
58
+ subject.job_count.must_equal(131)
59
+ subject.workers.must_equal(5)
49
60
  end
50
61
  end
51
62
 
52
63
  describe "scaling down" do
53
-
54
64
  it "from 31 workers" do
55
- with_app do |app|
56
- # add jobs to queue
57
- 31.times{ QC.enqueue("Time.now") }
58
- subject.workers.must_equal(3)
59
-
60
- # do work and scale back down
61
- 31.times{ QC::Worker.new.work }
62
- subject.job_count.must_equal(0)
63
- subject.workers.must_equal(0)
64
- end
65
+ # add jobs to queue
66
+ 31.times{ QC.enqueue("Time.now") }
67
+ subject.workers.must_equal(3)
68
+
69
+ # do work and scale back down
70
+ 31.times{ QC::Worker.new.work }
71
+ subject.job_count.must_equal(0)
72
+ subject.workers.must_equal(0)
65
73
  end
66
-
67
74
  end
68
75
 
69
76
  end
@@ -15,8 +15,4 @@ describe Autoscale do
15
15
  subject.scale.must_equal [1, 15, 30, 40, 50]
16
16
  end
17
17
 
18
- it "should have active" do
19
- subject.active.must_equal true
20
- end
21
-
22
18
  end
data/test/test_helper.rb CHANGED
@@ -17,23 +17,6 @@ Autoscale.config do |c|
17
17
  c.app = "racehq-test"
18
18
  c.mock = true
19
19
  c.scale = [1, 15, 30, 40, 50]
20
- c.active = true
21
20
  end
22
21
 
23
- # borrowed from heroku-api test helper
24
- def with_app(params={}, &block)
25
- params.merge!('name' => Autoscale.app) unless params.key?("name")
26
- heroku = Autoscale::Heroku.client
27
-
28
- begin
29
- data = heroku.post_app(params).body
30
- @name = data['name']
31
- ready = false
32
- until ready
33
- ready = heroku.request(:method => :put, :path => "/apps/#{@name}/status").status == 201
34
- end
35
- yield(data)
36
- ensure
37
- heroku.delete_app(@name) rescue nil
38
- end
39
- end
22
+ Autoscale.activate!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-qc-autoscale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: 3927445807195802384
163
+ hash: 3252771501108507673
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements:
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  segments:
171
171
  - 0
172
- hash: 3927445807195802384
172
+ hash: 3252771501108507673
173
173
  requirements: []
174
174
  rubyforge_project: heroku-qc-autoscale
175
175
  rubygems_version: 1.8.21