dyno_scaler 0.1.0 → 0.2.0

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/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3-p0@dyno_scaler --create
1
+ rvm use 1.9.3@dyno_scaler --create
data/Gemfile.lock CHANGED
@@ -1,117 +1,76 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dyno_scaler (0.1.0)
4
+ dyno_scaler (0.2.0)
5
5
  activesupport
6
6
  heroku-api
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionmailer (3.2.9)
12
- actionpack (= 3.2.9)
13
- mail (~> 2.4.4)
14
- actionpack (3.2.9)
15
- activemodel (= 3.2.9)
16
- activesupport (= 3.2.9)
11
+ actionmailer (0.6.1)
12
+ actionpack (>= 0.9.5)
13
+ actionpack (1.4.0)
14
+ activemodel (3.2.13)
15
+ activesupport (= 3.2.13)
17
16
  builder (~> 3.0.0)
18
- erubis (~> 2.7.0)
19
- journey (~> 1.0.4)
20
- rack (~> 1.4.0)
21
- rack-cache (~> 1.2)
22
- rack-test (~> 0.6.1)
23
- sprockets (~> 2.2.1)
24
- activemodel (3.2.9)
25
- activesupport (= 3.2.9)
26
- builder (~> 3.0.0)
27
- activerecord (3.2.9)
28
- activemodel (= 3.2.9)
29
- activesupport (= 3.2.9)
17
+ activerecord (3.2.13)
18
+ activemodel (= 3.2.13)
19
+ activesupport (= 3.2.13)
30
20
  arel (~> 3.0.2)
31
21
  tzinfo (~> 0.3.29)
32
- activeresource (3.2.9)
33
- activemodel (= 3.2.9)
34
- activesupport (= 3.2.9)
35
- activesupport (3.2.9)
36
- i18n (~> 0.6)
22
+ activesupport (3.2.13)
23
+ i18n (= 0.6.1)
37
24
  multi_json (~> 1.0)
38
25
  arel (3.0.2)
39
- bouncy-castle-java (1.5.0146.1)
26
+ bouncy-castle-java (1.5.0147)
40
27
  builder (3.0.4)
41
28
  columnize (0.3.6)
42
- connection_pool (0.9.3)
43
- debugger (1.2.2)
29
+ connection_pool (1.0.0)
30
+ debugger (1.6.0)
44
31
  columnize (>= 0.3.1)
45
- debugger-linecache (~> 1.1.1)
46
- debugger-ruby_core_source (~> 1.1.5)
47
- debugger-linecache (1.1.2)
48
- debugger-ruby_core_source (>= 1.1.1)
49
- debugger-ruby_core_source (1.1.5)
50
- diff-lcs (1.1.3)
51
- erubis (2.7.0)
52
- excon (0.16.10)
53
- girl_friday (0.11.1)
54
- connection_pool (~> 0.9.0)
32
+ debugger-linecache (~> 1.2.0)
33
+ debugger-ruby_core_source (~> 1.2.1)
34
+ debugger-linecache (1.2.0)
35
+ debugger-ruby_core_source (1.2.2)
36
+ diff-lcs (1.2.4)
37
+ excon (0.22.1)
38
+ girl_friday (0.11.2)
39
+ connection_pool (~> 1.0)
55
40
  rubinius-actor
56
- heroku-api (0.3.7)
57
- excon (~> 0.16.10)
58
- hike (1.2.1)
41
+ heroku-api (0.3.11)
42
+ excon (~> 0.22.1)
59
43
  i18n (0.6.1)
60
- journey (1.0.4)
61
- jruby-openssl (0.8.2)
62
- bouncy-castle-java (>= 1.5.0146.1)
63
- json (1.7.5)
64
- json (1.7.5-java)
65
- mail (2.4.4)
66
- i18n (>= 0.4.0)
67
- mime-types (~> 1.16)
68
- treetop (~> 1.4.8)
69
- mime-types (1.19)
70
- multi_json (1.5.0)
71
- polyglot (0.3.3)
72
- rack (1.4.1)
73
- rack-cache (1.2)
74
- rack (>= 0.4)
75
- rack-protection (1.3.2)
76
- rack
77
- rack-ssl (1.3.2)
44
+ jruby-openssl (0.8.8)
45
+ bouncy-castle-java (>= 1.5.0147)
46
+ mono_logger (1.1.0)
47
+ multi_json (1.7.4)
48
+ rack (1.5.2)
49
+ rack-protection (1.5.0)
78
50
  rack
79
- rack-test (0.6.2)
80
- rack (>= 1.0)
81
- rails (3.2.9)
82
- actionmailer (= 3.2.9)
83
- actionpack (= 3.2.9)
84
- activerecord (= 3.2.9)
85
- activeresource (= 3.2.9)
86
- activesupport (= 3.2.9)
87
- bundler (~> 1.0)
88
- railties (= 3.2.9)
89
- railties (3.2.9)
90
- actionpack (= 3.2.9)
91
- activesupport (= 3.2.9)
92
- rack-ssl (~> 1.3.2)
93
- rake (>= 0.8.7)
94
- rdoc (~> 3.4)
95
- thor (>= 0.14.6, < 2.0)
96
- rake (10.0.3)
97
- rdoc (3.12)
98
- json (~> 1.4)
99
- redis (3.0.2)
100
- redis-namespace (1.2.1)
51
+ rails (0.9.5)
52
+ actionmailer (>= 0.6.1)
53
+ actionpack (>= 1.4.0)
54
+ activerecord (>= 1.6.0)
55
+ rake (>= 0.4.15)
56
+ rake (10.0.4)
57
+ redis (3.0.4)
58
+ redis-namespace (1.3.0)
101
59
  redis (~> 3.0.0)
102
- resque (1.23.0)
60
+ resque (1.24.1)
61
+ mono_logger (~> 1.0)
103
62
  multi_json (~> 1.0)
104
- redis-namespace (~> 1.0)
63
+ redis-namespace (~> 1.2)
105
64
  sinatra (>= 0.9.2)
106
65
  vegas (~> 0.1.2)
107
- rspec (2.12.0)
108
- rspec-core (~> 2.12.0)
109
- rspec-expectations (~> 2.12.0)
110
- rspec-mocks (~> 2.12.0)
111
- rspec-core (2.12.2)
112
- rspec-expectations (2.12.1)
113
- diff-lcs (~> 1.1.3)
114
- rspec-mocks (2.12.1)
66
+ rspec (2.13.0)
67
+ rspec-core (~> 2.13.0)
68
+ rspec-expectations (~> 2.13.0)
69
+ rspec-mocks (~> 2.13.0)
70
+ rspec-core (2.13.1)
71
+ rspec-expectations (2.13.0)
72
+ diff-lcs (>= 1.1.3, < 2.0)
73
+ rspec-mocks (2.13.1)
115
74
  rubinius-actor (0.0.2)
116
75
  rubinius-core-api
117
76
  rubinius-core-api (0.0.1)
@@ -124,21 +83,12 @@ GEM
124
83
  multi_json (~> 1.0)
125
84
  simplecov-html (~> 0.7.1)
126
85
  simplecov-html (0.7.1)
127
- sinatra (1.3.3)
128
- rack (~> 1.3, >= 1.3.6)
129
- rack-protection (~> 1.2)
130
- tilt (~> 1.3, >= 1.3.3)
131
- sprockets (2.2.2)
132
- hike (~> 1.2)
133
- multi_json (~> 1.0)
134
- rack (~> 1.0)
135
- tilt (~> 1.1, != 1.3.0)
136
- thor (0.16.0)
137
- tilt (1.3.3)
138
- treetop (1.4.12)
139
- polyglot
140
- polyglot (>= 0.3.1)
141
- tzinfo (0.3.35)
86
+ sinatra (1.4.2)
87
+ rack (~> 1.5, >= 1.5.2)
88
+ rack-protection (~> 1.4)
89
+ tilt (~> 1.3, >= 1.3.4)
90
+ tilt (1.4.1)
91
+ tzinfo (0.3.37)
142
92
  vegas (0.1.11)
143
93
  rack (>= 1.0.0)
144
94
 
data/README.md CHANGED
@@ -70,7 +70,7 @@ pending jobs, and working jobs.
70
70
  When deploying to heroku you'll want to add these two configuration keys:
71
71
 
72
72
  HEROKU_API_KEY=<YOUR-API-KEY-HERE>
73
- HEROKU_APPLICATION=<THE-NAME-OF-YOUR-APP-ON-HEROKU-HERE>
73
+ HEROKU_APP=<THE-NAME-OF-YOUR-APP-ON-HEROKU-HERE>
74
74
 
75
75
  They are used by the [heroku-api](https://github.com/heroku/heroku.rb) gem to
76
76
  scale dynos of your application.
@@ -92,7 +92,9 @@ hash that can be passed to the `DynoScaler::Manager#scale_with` method, like so:
92
92
  DynoScaler.manager.scale_with(options)
93
93
  end
94
94
 
95
- config.dyno_scaler.async { MY_QUEUE << options }
95
+ config.dyno_scaler.async do |options|
96
+ MY_QUEUE << options
97
+ end
96
98
 
97
99
  ## Contributing
98
100
 
@@ -2,19 +2,26 @@
2
2
 
3
3
  module DynoScaler
4
4
  class Heroku
5
- attr_accessor :application
5
+ attr_accessor :application, :options
6
6
 
7
- def initialize(application)
7
+ def initialize(application, options={})
8
8
  self.application = application
9
+ self.options = options || {}
9
10
  end
10
11
 
11
12
  def scale_workers(quantity)
12
13
  heroku_client.post_ps_scale(application, 'worker', quantity)
13
14
  end
14
15
 
16
+ def running_workers
17
+ heroku_client.get_ps(application).body.select do |process|
18
+ process['process'].start_with?('worker')
19
+ end.count
20
+ end
21
+
15
22
  protected
16
23
  def heroku_client
17
- @heroku_client ||= ::Heroku::API.new
24
+ @heroku_client ||= ::Heroku::API.new(options)
18
25
  end
19
26
  end
20
27
  end
@@ -37,6 +37,10 @@ module DynoScaler
37
37
  send(action, options) if action
38
38
  end
39
39
 
40
+ def running_workers
41
+ heroku.running_workers
42
+ end
43
+
40
44
  protected
41
45
  def config
42
46
  DynoScaler.configuration
@@ -1,3 +1,3 @@
1
1
  module DynoScaler
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,15 +2,16 @@ require "spec_helper"
2
2
 
3
3
  describe DynoScaler::Heroku do
4
4
  let(:application) { 'my-application-on-heroku' }
5
- subject(:heroku_client) { DynoScaler::Heroku.new application }
5
+ let(:options) { nil }
6
+ subject(:heroku_client) { DynoScaler::Heroku.new application, options }
6
7
 
7
- let(:heroku_api) { mock(::Heroku::API, :post_ps_scale => false) }
8
+ describe "scaling workers" do
9
+ let(:heroku_api) { mock(::Heroku::API, :post_ps_scale => false) }
8
10
 
9
- before do
10
- ::Heroku::API.stub!(:new).and_return(heroku_api)
11
- end
11
+ before do
12
+ ::Heroku::API.stub!(:new).and_return(heroku_api)
13
+ end
12
14
 
13
- describe "scaling workers" do
14
15
  let(:quantity) { 2 }
15
16
 
16
17
  it "scales workers of the application to the given number of workers" do
@@ -18,5 +19,25 @@ describe DynoScaler::Heroku do
18
19
  heroku_client.scale_workers(quantity)
19
20
  end
20
21
  end
22
+
23
+ describe "getting number of running workers" do
24
+ let(:options) { { mock: true } } # Mock Excon http requests
25
+
26
+ before { Excon.stub({method: :get}, {body: body, status: 200}) }
27
+
28
+ context "when there are running workers" do
29
+ let(:body) do
30
+ [{"process"=>"web.1"}, {"process"=>"worker.1"}, {"process"=>"worker.2"}]
31
+ end
32
+
33
+ its(:running_workers) { should eq(2) }
34
+ end
35
+
36
+ context "when there are no running workers" do
37
+ let(:body) { [{"process"=>"web.1"}] }
38
+
39
+ its(:running_workers) { should be_zero }
40
+ end
41
+ end
21
42
  end
22
43
 
@@ -346,4 +346,10 @@ describe DynoScaler::Manager do
346
346
  end
347
347
  end
348
348
  end
349
+
350
+ describe "running workers" do
351
+ let(:heroku) { mock(DynoScaler::Heroku, scale_workers: false, running_workers: 2) }
352
+
353
+ its(:running_workers) { should eq(heroku.running_workers) }
354
+ end
349
355
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyno_scaler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: heroku-api
@@ -134,15 +134,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  - - ! '>='
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
+ segments:
138
+ - 0
139
+ hash: 2224126621468173424
137
140
  required_rubygems_version: !ruby/object:Gem::Requirement
138
141
  none: false
139
142
  requirements:
140
143
  - - ! '>='
141
144
  - !ruby/object:Gem::Version
142
145
  version: '0'
146
+ segments:
147
+ - 0
148
+ hash: 2224126621468173424
143
149
  requirements: []
144
150
  rubyforge_project:
145
- rubygems_version: 1.8.24
151
+ rubygems_version: 1.8.25
146
152
  signing_key:
147
153
  specification_version: 3
148
154
  summary: Scale your dyno workers on Heroku as needed