heroku_resque_autoscaler 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a613c71641b59071fcd4c1fc538a68f9cfda9319
4
- data.tar.gz: 360442559f1a22ebf96ce90de9007c8769845de2
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWZhN2Y4MjRjOWE1YTAzZWZmMzkzMTdmZTJjOWQ2MjQ1ZmRiMjdlOQ==
5
+ data.tar.gz: !binary |-
6
+ Yjc4N2QzOTBlN2QyYjhjZTFjYTY2ZTdlMWM2MTIyYjBkOTQ1NTQ2Nw==
5
7
  SHA512:
6
- metadata.gz: b6a60327b925f9e11f0c482c3ba0d6f94595bef48882e96ccf7688637b053fa3430583ef08666ede7d3f404da676564073d663cc06ed8b70853ca687efd71bc3
7
- data.tar.gz: cf96ced05969bc7635932249af6609579df5bcf2ef0e7ad55ee310d307e57cbfd60e98213e6f288e913485172e4f687b5de411379e92fb41c5f965f9d27b6a39
8
+ metadata.gz: !binary |-
9
+ YTQ4MjFjYmM1YjhmOTUzMzE2MDRjMzBiNWZmYjZiODA5YjE2NDFjMDhmMTg1
10
+ NTliODM1NDMzMzk3OGU2YmZhY2E0MWI2NTlhMjRmNjQ5ZTE1YTE4Y2I0ZTJh
11
+ ZmZmZjM0NDFlYzUzNmU1YThlMzhlYjIwMmNjODIzODQwMGUwYmM=
12
+ data.tar.gz: !binary |-
13
+ NDZjYzE3NGM4ZDY0NTM5MDU0OWMwNDdjYTc0MzhiODIyMzEyMGUzYWY1NWI0
14
+ N2I4YmYzNmUwOTNmMjFmNjQyODU3MWY4OWQyYWRkNzA5MTIwODllOTQzMzJk
15
+ NWM2Mjk1ZmUxNDJiOTE0OTdmMGFmMmJmY2JkYTUyNTc0Y2U1NGM=
@@ -1,3 +1,4 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
4
  - 1.9.3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in heroku_resque_autoscaler.gemspec
4
- gemspec
4
+ gemspec
data/README.md CHANGED
@@ -11,7 +11,7 @@ Inspired by [@darkhelmet](https://github.com/darkhelmet)'s
11
11
 
12
12
  ## Current Version
13
13
 
14
- 0.1.1
14
+ 0.1.2
15
15
 
16
16
 
17
17
  ## Requirements
@@ -69,11 +69,19 @@ class AutoscaledJob
69
69
  end
70
70
  ```
71
71
 
72
+ You can optionally configure a maximum number of workers to scale up to in your configuration block.
73
+
74
+ ```ruby
75
+ HerokuResqueAutoscaler.configure do |config|
76
+ config.max_resque_workers = ENV["MAX_RESQUE_WORKERS"]
77
+ end
78
+ ```
72
79
 
73
80
  ## Authors
74
81
 
75
82
  * Jessica Lynn Suttles / [@jlsuttles](https://github.com/jlsuttles)
76
83
  * Bookis Smuin / [@bookis](https://github.com/bookis)
84
+ * Chris Stringer / [@jcstringer](https://github.com/jcstringer)
77
85
 
78
86
 
79
87
  ## Contributing
@@ -3,13 +3,13 @@ require "heroku_resque_autoscaler/configuration"
3
3
  require "heroku_resque_autoscaler/scaler"
4
4
 
5
5
  module HerokuResqueAutoscaler
6
- WORKER_SCALE = [
7
- { :workers => 1, :job_count => 1 },
8
- { :workers => 2, :job_count => 15 },
9
- { :workers => 3, :job_count => 25 },
10
- { :workers => 4, :job_count => 40 },
11
- { :workers => 5, :job_count => 60 }
12
- ]
6
+ DEFAULT_WORKER_SCALE = [
7
+ { :workers => 1, :job_count => 1 },
8
+ { :workers => 2, :job_count => 15 },
9
+ { :workers => 3, :job_count => 25 },
10
+ { :workers => 4, :job_count => 40 },
11
+ { :workers => 5, :job_count => 60 }
12
+ ]
13
13
 
14
14
  class << self
15
15
  # A HerokuResqueAutoscaler configuration object. Must act like a hash and
@@ -50,7 +50,7 @@ module HerokuResqueAutoscaler
50
50
  end
51
51
 
52
52
  def num_desired_heroku_workers(*args)
53
- WORKER_SCALE.reverse_each do |scale_info|
53
+ worker_scale.reverse_each do |scale_info|
54
54
  if Scaler.job_count >= scale_info[:job_count]
55
55
  return scale_info[:workers]
56
56
  end
@@ -58,4 +58,13 @@ module HerokuResqueAutoscaler
58
58
 
59
59
  0
60
60
  end
61
+
62
+ private
63
+
64
+ def worker_scale
65
+ ## Respect a max number of workers if this is configured
66
+ DEFAULT_WORKER_SCALE.reject do |w|
67
+ w[:workers] > Scaler.max_resque_workers
68
+ end
69
+ end
61
70
  end
@@ -3,6 +3,7 @@ module HerokuResqueAutoscaler
3
3
  OPTIONS = {
4
4
  heroku_api_key: ENV["HEROKU_API_KEY"],
5
5
  heroku_app_name: ENV["HEROKU_APP_NAME"],
6
+ max_resque_workers: ENV["MAX_RESQUE_WORKERS"]
6
7
  }
7
8
 
8
9
  # Defines accessors for all OPTIONS
@@ -10,7 +11,7 @@ module HerokuResqueAutoscaler
10
11
  attr_accessor key
11
12
  end
12
13
 
13
- # Initializes defaults to be the environment varibales of the same names
14
+ # Initializes defaults to be the environment variables of the same names
14
15
  def initialize
15
16
  OPTIONS.each_pair do |key, value|
16
17
  self.send("#{key}=", value)
@@ -16,6 +16,11 @@ module HerokuResqueAutoscaler
16
16
  HerokuResqueAutoscaler.configuration["heroku_app_name"]
17
17
  end
18
18
 
19
+ def max_resque_workers
20
+ return Float::INFINITY unless HerokuResqueAutoscaler.configuration["max_resque_workers"]
21
+ HerokuResqueAutoscaler.configuration["max_resque_workers"].to_i
22
+ end
23
+
19
24
  def workers
20
25
  heroku.get_ps(app_name).body.keep_if do |ps|
21
26
  ps["process"] =~ /worker/
@@ -1,3 +1,3 @@
1
1
  module HerokuResqueAutoscaler
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -11,6 +11,10 @@ describe HerokuResqueAutoscaler::Configuration do
11
11
  assert_config_default :heroku_api_key, ENV["HEROKU_API_KEY"]
12
12
  end
13
13
 
14
+ it "defaults to no max resque workers" do
15
+ assert_config_default :max_resque_workers, nil
16
+ end
17
+
14
18
  it "allows values to be overwritten" do
15
19
  assert_config_overridable :heroku_api_key
16
20
  end
@@ -9,13 +9,16 @@ class HerokuResqueAutoscalerTestClass
9
9
  end
10
10
 
11
11
  describe HerokuResqueAutoscaler do
12
- before :each do
12
+ let(:max_resque_workers) { nil }
13
+
14
+ before do
13
15
  @heroku = mock(Heroku::API)
14
16
  HerokuResqueAutoscaler::Scaler.stub(:heroku).and_return(@heroku)
15
17
 
16
18
  HerokuResqueAutoscaler.configure do |config|
17
19
  config.heroku_api_key = "api-key"
18
20
  config.heroku_app_name = "app-name"
21
+ config.max_resque_workers = max_resque_workers
19
22
  end
20
23
  end
21
24
 
@@ -33,6 +36,14 @@ describe HerokuResqueAutoscaler do
33
36
  end
34
37
  end
35
38
 
39
+ context ".max_resque_workers" do
40
+ let(:max_resque_workers) { "2" }
41
+
42
+ it "returns a count" do
43
+ HerokuResqueAutoscaler::Scaler.max_resque_workers.should == 2
44
+ end
45
+ end
46
+
36
47
  context ".workers" do
37
48
  it "returns the number of workers from the Heroku application" do
38
49
  Excon.stub(method: :get) do |params|
@@ -123,6 +134,19 @@ describe HerokuResqueAutoscaler do
123
134
  end
124
135
 
125
136
  context ".after_enqueue_scale_up" do
137
+ context "with max_resque_workers set" do
138
+ let(:max_resque_workers) { 5 }
139
+
140
+ it "scales with a max" do
141
+ num_workers = 5
142
+ num_desired_workers = 6
143
+ HerokuResqueAutoscaler::Scaler.stub(:workers).and_return(num_workers)
144
+ HerokuResqueAutoscaler::Scaler.stub(:job_count).and_return(num_workers)
145
+ HerokuResqueAutoscaler::Scaler.should_not_receive(:workers=).with(num_desired_workers)
146
+ HerokuResqueAutoscalerTestClass.after_enqueue_scale_up
147
+ end
148
+ end
149
+
126
150
  it "ups the amount of workers if there are not enough" do
127
151
  num_workers = 5
128
152
  num_desired_workers = 6
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_resque_autoscaler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessica Lynn Suttles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: heroku-api
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.3.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: resque
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.7.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.7.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.11.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.11.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rb-fsevent
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.9.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.9.2
97
97
  description: Uses Resque Job Hooks and the Heroku API gem to autoscale Heroku Resque
@@ -102,9 +102,9 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".gitignore"
106
- - ".rspec"
107
- - ".travis.yml"
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
108
  - Gemfile
109
109
  - LICENSE
110
110
  - README.md
@@ -127,17 +127,17 @@ require_paths:
127
127
  - lib
128
128
  required_ruby_version: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - ">="
130
+ - - ! '>='
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - ">="
135
+ - - ! '>='
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubyforge_project:
140
- rubygems_version: 2.2.2
140
+ rubygems_version: 2.4.8
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Uses Resque Job Hooks and the Heroku API gem to autoscale Heroku Resque workers