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 +2 -1
- data/lib/autoscale/heroku.rb +1 -1
- data/lib/heroku-qc-autoscale/version.rb +1 -1
- data/lib/heroku-qc-autoscale.rb +2 -3
- data/test/autoscale/heroku_test.rb +41 -34
- data/test/autoscale_test.rb +0 -4
- data/test/test_helper.rb +1 -18
- metadata +3 -3
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
|
|
data/lib/autoscale/heroku.rb
CHANGED
data/lib/heroku-qc-autoscale.rb
CHANGED
@@ -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
|
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
|
-
|
14
|
-
|
15
|
-
subject.workers.must_equal(1)
|
30
|
+
subject.workers = 1
|
31
|
+
subject.workers.must_equal(1)
|
16
32
|
|
17
|
-
|
18
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
data/test/autoscale_test.rb
CHANGED
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
|
-
|
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.
|
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:
|
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:
|
172
|
+
hash: 3252771501108507673
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project: heroku-qc-autoscale
|
175
175
|
rubygems_version: 1.8.21
|