heroku-resque-workers-scaler 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -88
- data/README.md +29 -4
- data/{scaler_config.yml → config/scaler_config.yml} +3 -1
- data/heroku-resque-workers-scaler.gemspec +27 -25
- data/lib/heroku-resque-workers-scaler/config.rb +19 -36
- data/lib/heroku-resque-workers-scaler/scaler.rb +14 -5
- data/lib/heroku-resque-workers-scaler/version.rb +2 -2
- data/spec/heroku-resque-workers-scaler/config_spec.rb +3 -16
- data/spec/heroku-resque-workers-scaler/scaler_spec.rb +27 -30
- data/spec/spec_helper.rb +8 -8
- metadata +28 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8dc50d2ecf4710e742e167c733230ed00e3bcae
|
|
4
|
+
data.tar.gz: 7556b47f8cf4039e8a864b86397bd46e0690b20b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1e449b8d91ae50b69d2e839b84535fe4bdde196196277b873ffe409a6e3e7361e9cb343c947b7c6f9e486d180b97d4c85ea45201cec93eb733f0e51d2d922fd
|
|
7
|
+
data.tar.gz: fca194c6dd9d4b8dc1e57c717602c06f4c7f179a73c1589dca8fd643c6a4e6916cab266e97696f54428a7608061d34c7829058fbf8f303dacdd68b0706a5503e
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,42 +1,15 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
heroku-resque-workers-scaler (0.1
|
|
5
|
-
platform-api
|
|
6
|
-
resque
|
|
4
|
+
heroku-resque-workers-scaler (0.2.1)
|
|
5
|
+
platform-api (~> 0.2.0)
|
|
6
|
+
resque (~> 1.25.2)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionmailer (4.1.1)
|
|
12
|
-
actionpack (= 4.1.1)
|
|
13
|
-
actionview (= 4.1.1)
|
|
14
|
-
mail (~> 2.5.4)
|
|
15
|
-
actionpack (4.1.1)
|
|
16
|
-
actionview (= 4.1.1)
|
|
17
|
-
activesupport (= 4.1.1)
|
|
18
|
-
rack (~> 1.5.2)
|
|
19
|
-
rack-test (~> 0.6.2)
|
|
20
|
-
actionview (4.1.1)
|
|
21
|
-
activesupport (= 4.1.1)
|
|
22
|
-
builder (~> 3.1)
|
|
23
|
-
erubis (~> 2.7.0)
|
|
24
|
-
activemodel (4.1.1)
|
|
25
|
-
activesupport (= 4.1.1)
|
|
26
|
-
builder (~> 3.1)
|
|
27
|
-
activerecord (4.1.1)
|
|
28
|
-
activemodel (= 4.1.1)
|
|
29
|
-
activesupport (= 4.1.1)
|
|
30
|
-
arel (~> 5.0.0)
|
|
31
|
-
activesupport (4.1.1)
|
|
32
|
-
i18n (~> 0.6, >= 0.6.9)
|
|
33
|
-
json (~> 1.7, >= 1.7.7)
|
|
34
|
-
minitest (~> 5.1)
|
|
35
|
-
thread_safe (~> 0.1)
|
|
36
|
-
tzinfo (~> 1.1)
|
|
37
11
|
addressable (2.3.6)
|
|
38
|
-
|
|
39
|
-
builder (3.2.2)
|
|
12
|
+
coderay (1.1.0)
|
|
40
13
|
crack (0.4.2)
|
|
41
14
|
safe_yaml (~> 1.0.0)
|
|
42
15
|
diff-lcs (1.2.5)
|
|
@@ -48,42 +21,21 @@ GEM
|
|
|
48
21
|
moneta
|
|
49
22
|
multi_json (>= 1.9.2)
|
|
50
23
|
netrc
|
|
51
|
-
|
|
52
|
-
i18n (0.6.9)
|
|
53
|
-
json (1.8.1)
|
|
54
|
-
mail (2.5.4)
|
|
55
|
-
mime-types (~> 1.16)
|
|
56
|
-
treetop (~> 1.4.8)
|
|
57
|
-
mime-types (1.25.1)
|
|
58
|
-
minitest (5.3.4)
|
|
24
|
+
method_source (0.8.2)
|
|
59
25
|
moneta (0.8.0)
|
|
60
26
|
mono_logger (1.1.0)
|
|
61
|
-
multi_json (1.10.
|
|
27
|
+
multi_json (1.10.1)
|
|
62
28
|
netrc (0.7.7)
|
|
63
29
|
platform-api (0.2.0)
|
|
64
30
|
heroics (~> 0.0.10)
|
|
65
|
-
|
|
66
|
-
|
|
31
|
+
pry (0.10.1)
|
|
32
|
+
coderay (~> 1.1.0)
|
|
33
|
+
method_source (~> 0.8.1)
|
|
34
|
+
slop (~> 3.4)
|
|
35
|
+
psych (2.0.6)
|
|
67
36
|
rack (1.5.2)
|
|
68
37
|
rack-protection (1.5.3)
|
|
69
38
|
rack
|
|
70
|
-
rack-test (0.6.2)
|
|
71
|
-
rack (>= 1.0)
|
|
72
|
-
rails (4.1.1)
|
|
73
|
-
actionmailer (= 4.1.1)
|
|
74
|
-
actionpack (= 4.1.1)
|
|
75
|
-
actionview (= 4.1.1)
|
|
76
|
-
activemodel (= 4.1.1)
|
|
77
|
-
activerecord (= 4.1.1)
|
|
78
|
-
activesupport (= 4.1.1)
|
|
79
|
-
bundler (>= 1.3.0, < 2.0)
|
|
80
|
-
railties (= 4.1.1)
|
|
81
|
-
sprockets-rails (~> 2.0)
|
|
82
|
-
railties (4.1.1)
|
|
83
|
-
actionpack (= 4.1.1)
|
|
84
|
-
activesupport (= 4.1.1)
|
|
85
|
-
rake (>= 0.8.7)
|
|
86
|
-
thor (>= 0.18.1, < 2.0)
|
|
87
39
|
rake (10.3.2)
|
|
88
40
|
redis (3.1.0)
|
|
89
41
|
redis-namespace (1.5.1)
|
|
@@ -94,36 +46,25 @@ GEM
|
|
|
94
46
|
redis-namespace (~> 1.3)
|
|
95
47
|
sinatra (>= 0.9.2)
|
|
96
48
|
vegas (~> 0.1.2)
|
|
97
|
-
rspec (
|
|
98
|
-
rspec-core (~>
|
|
99
|
-
rspec-expectations (~>
|
|
100
|
-
rspec-mocks (~>
|
|
101
|
-
rspec-core (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
49
|
+
rspec (3.1.0)
|
|
50
|
+
rspec-core (~> 3.1.0)
|
|
51
|
+
rspec-expectations (~> 3.1.0)
|
|
52
|
+
rspec-mocks (~> 3.1.0)
|
|
53
|
+
rspec-core (3.1.3)
|
|
54
|
+
rspec-support (~> 3.1.0)
|
|
55
|
+
rspec-expectations (3.1.1)
|
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
57
|
+
rspec-support (~> 3.1.0)
|
|
58
|
+
rspec-mocks (3.1.0)
|
|
59
|
+
rspec-support (~> 3.1.0)
|
|
60
|
+
rspec-support (3.1.0)
|
|
105
61
|
safe_yaml (1.0.3)
|
|
106
62
|
sinatra (1.4.5)
|
|
107
63
|
rack (~> 1.4)
|
|
108
64
|
rack-protection (~> 1.4)
|
|
109
65
|
tilt (~> 1.3, >= 1.3.4)
|
|
110
|
-
|
|
111
|
-
hike (~> 1.2)
|
|
112
|
-
multi_json (~> 1.0)
|
|
113
|
-
rack (~> 1.0)
|
|
114
|
-
tilt (~> 1.1, != 1.3.0)
|
|
115
|
-
sprockets-rails (2.1.3)
|
|
116
|
-
actionpack (>= 3.0)
|
|
117
|
-
activesupport (>= 3.0)
|
|
118
|
-
sprockets (~> 2.8)
|
|
119
|
-
thor (0.19.1)
|
|
120
|
-
thread_safe (0.3.3)
|
|
66
|
+
slop (3.6.0)
|
|
121
67
|
tilt (1.4.1)
|
|
122
|
-
treetop (1.4.15)
|
|
123
|
-
polyglot
|
|
124
|
-
polyglot (>= 0.3.1)
|
|
125
|
-
tzinfo (1.1.0)
|
|
126
|
-
thread_safe (~> 0.1)
|
|
127
68
|
vegas (0.1.11)
|
|
128
69
|
rack (>= 1.0.0)
|
|
129
70
|
webmock (1.18.0)
|
|
@@ -135,8 +76,8 @@ PLATFORMS
|
|
|
135
76
|
|
|
136
77
|
DEPENDENCIES
|
|
137
78
|
heroku-resque-workers-scaler!
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
rake
|
|
141
|
-
rspec
|
|
142
|
-
webmock
|
|
79
|
+
pry
|
|
80
|
+
psych (~> 2.0.6)
|
|
81
|
+
rake (~> 10.3.2)
|
|
82
|
+
rspec (~> 3.1.0)
|
|
83
|
+
webmock (~> 1.18.0)
|
data/README.md
CHANGED
|
@@ -15,19 +15,45 @@ On fork => https://github.com/joel/heroku-resque-workers-scaler
|
|
|
15
15
|
* I've switched to Rspec from TestUnit
|
|
16
16
|
* I've switched to HerokuAPI Gem instead of Heroku Client Gem
|
|
17
17
|
* Add safe mode for heroku
|
|
18
|
+
* See CHANGELOG
|
|
18
19
|
|
|
19
20
|
### Configuration :
|
|
20
21
|
|
|
21
22
|
You need to defined two vars for your heroku :
|
|
22
23
|
|
|
23
|
-
Go to your https://api.heroku.com/account
|
|
24
|
+
`Go to your https://api.heroku.com/account`
|
|
25
|
+
|
|
26
|
+
```
|
|
24
27
|
heroku config:add HEROKU_API_KEY=your_api_key -a your_app_name
|
|
25
28
|
heroku config:add HEROKU_APP_NAME=your_app_name -a your_app_name
|
|
29
|
+
heroku config:add export SAFE_MODE=true -a your_app_name
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Run localy
|
|
26
33
|
|
|
27
34
|
You can test when executed this :
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
export HEROKU_API_KEY=your_api_key
|
|
38
|
+
export HEROKU_APP_NAME=your_app_name
|
|
39
|
+
export SAFE_MODE=true
|
|
40
|
+
export ENVIRONMENT=development
|
|
28
41
|
```
|
|
29
|
-
|
|
42
|
+
open `irb`
|
|
43
|
+
|
|
30
44
|
```
|
|
45
|
+
irb -r heroku-resque-workers-scaler -I ./lib
|
|
46
|
+
```
|
|
47
|
+
play with commands
|
|
48
|
+
```
|
|
49
|
+
>> HerokuResqueAutoScale::Scaler.workers
|
|
50
|
+
=> 0
|
|
51
|
+
>> HerokuResqueAutoScale::Scaler.workers=1
|
|
52
|
+
=> 1
|
|
53
|
+
>> HerokuResqueAutoScale::Scaler.workers=0
|
|
54
|
+
=> 0
|
|
55
|
+
```
|
|
56
|
+
|
|
31
57
|
You can change the thresholds, environments of execution and the name of your worker process in your project on config/scaler_config.yml
|
|
32
58
|
|
|
33
59
|
Exmple YAML file contents:
|
|
@@ -40,7 +66,7 @@ Exmple YAML file contents:
|
|
|
40
66
|
environments:
|
|
41
67
|
- production
|
|
42
68
|
worker_name: resque
|
|
43
|
-
|
|
69
|
+
|
|
44
70
|
I just bundled it into a gem for easy inclusion into other projects.
|
|
45
71
|
|
|
46
72
|
#### Usage
|
|
@@ -75,4 +101,3 @@ When you ask heroku for scale down workers, heroku send SIGTERM and wait 4 secon
|
|
|
75
101
|
|
|
76
102
|
Copyright (c) 2010 Mark Quezada. See LICENSE.txt for
|
|
77
103
|
further details.
|
|
78
|
-
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
require File.expand_path('../lib/heroku-resque-workers-scaler/version', __FILE__)
|
|
1
|
+
require_relative 'lib/heroku-resque-workers-scaler/version'
|
|
3
2
|
|
|
4
|
-
Gem::Specification.new do |
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
gem.files = `git ls-files`.split($\)
|
|
13
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
14
|
-
gem.test_files = gem.files.grep(%r{^(spec)/})
|
|
15
|
-
gem.name = 'heroku-resque-workers-scaler'
|
|
16
|
-
gem.require_paths = ['lib']
|
|
17
|
-
gem.version = HerokuResqueAutoScale::VERSION
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'heroku-resque-workers-scaler'
|
|
5
|
+
spec.version = HerokuResqueAutoScale::VERSION
|
|
6
|
+
spec.date = '2012-10-22'
|
|
7
|
+
spec.summary = %q{Simple helper for Rails App configuration}
|
|
8
|
+
spec.description = %q{Auto scale your resque workers on Heroku.}
|
|
9
|
+
spec.authors = ['Mark Quezada', 'Joel AZEMAR']
|
|
10
|
+
spec.email = ['mark@mirthlab.com', 'joel.azemar@gmail.com']
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
spec.homepage = 'https://github.com/joel/heroku-resque-workers-scaler'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files`.split($/)
|
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
|
18
|
+
spec.require_paths = ['lib']
|
|
19
|
+
|
|
20
|
+
spec.add_dependency 'resque', '~> 1.25.2'
|
|
21
|
+
spec.add_dependency 'platform-api', '~> 0.2.0'
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
|
24
|
+
spec.add_development_dependency 'webmock', '~> 1.18.0'
|
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.3.2'
|
|
26
|
+
spec.add_development_dependency 'psych', '~> 2.0.6'
|
|
27
|
+
|
|
28
|
+
# spec.required_ruby_version = '~> 2.1'
|
|
29
|
+
end
|
|
@@ -1,52 +1,35 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
1
3
|
module HerokuResqueAutoScale
|
|
2
4
|
module Config
|
|
3
5
|
extend self
|
|
4
|
-
|
|
6
|
+
|
|
5
7
|
CONFIG_FILE_NAME = 'scaler_config.yml'
|
|
6
|
-
|
|
8
|
+
|
|
7
9
|
def thresholds
|
|
8
|
-
@thresholds ||=
|
|
9
|
-
if config_file? && config.has_key?('thresholds')
|
|
10
|
-
config['thresholds']
|
|
11
|
-
else
|
|
12
|
-
[{workers:1,job_count:1},{workers:2,job_count:15},{workers:3,job_count:25},{workers:4,job_count:40},{workers:5,job_count:60}]
|
|
13
|
-
end
|
|
14
|
-
end
|
|
10
|
+
@thresholds ||= config['thresholds']
|
|
15
11
|
end
|
|
16
|
-
|
|
12
|
+
|
|
17
13
|
def environments
|
|
18
|
-
@environments ||=
|
|
19
|
-
if config_file? && config.has_key?('environments')
|
|
20
|
-
config['environments']
|
|
21
|
-
else
|
|
22
|
-
[ 'production' ]
|
|
23
|
-
end
|
|
24
|
-
end
|
|
14
|
+
@environments ||= config['environments']
|
|
25
15
|
end
|
|
26
16
|
|
|
27
17
|
def worker_name
|
|
28
|
-
@worker_name ||=
|
|
29
|
-
if config_file? && config.has_key?('worker_name')
|
|
30
|
-
config['worker_name']
|
|
31
|
-
else
|
|
32
|
-
'worker'
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def config_file?
|
|
40
|
-
@config_file ||= override? || File.exists?(CONFIG_FILE_NAME)
|
|
18
|
+
@worker_name ||= config['worker_name']
|
|
41
19
|
end
|
|
42
|
-
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
43
23
|
def config
|
|
44
|
-
@config ||=
|
|
24
|
+
@config ||= YAML.load_file(config_route_path)
|
|
45
25
|
end
|
|
46
|
-
|
|
47
|
-
def
|
|
48
|
-
File.exists?(Rails.root.join("config/#{CONFIG_FILE_NAME}").to_s)
|
|
26
|
+
|
|
27
|
+
def config_route_path
|
|
28
|
+
if defined?(Rails) && File.exists?(Rails.root.join("config/#{CONFIG_FILE_NAME}").to_s)
|
|
29
|
+
Rails.root.join("config/#{CONFIG_FILE_NAME}").to_s
|
|
30
|
+
else
|
|
31
|
+
File.expand_path("../../../config/#{CONFIG_FILE_NAME}", __FILE__)
|
|
32
|
+
end
|
|
49
33
|
end
|
|
50
34
|
end
|
|
51
35
|
end
|
|
52
|
-
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'platform-api'
|
|
2
|
+
require 'resque'
|
|
2
3
|
|
|
3
4
|
module HerokuResqueAutoScale
|
|
4
5
|
module Scaler
|
|
@@ -18,9 +19,9 @@ module HerokuResqueAutoScale
|
|
|
18
19
|
quantity = quantity.to_i
|
|
19
20
|
|
|
20
21
|
if safe_mode? and setting_this_number_of_workers_will_scale_down? quantity
|
|
21
|
-
return unless
|
|
22
|
+
return unless all_jobs_have_been_processed?
|
|
22
23
|
end
|
|
23
|
-
result = @@heroku.formation.update(app_name, worker_name, {quantity: quantity})
|
|
24
|
+
result = @@heroku.formation.update(app_name, worker_name, { quantity: quantity })
|
|
24
25
|
result['quantity'] == quantity
|
|
25
26
|
end
|
|
26
27
|
|
|
@@ -46,14 +47,22 @@ module HerokuResqueAutoScale
|
|
|
46
47
|
ENV['SAFE_MODE'] and ENV['SAFE_MODE'] == 'true'
|
|
47
48
|
end
|
|
48
49
|
|
|
49
|
-
def
|
|
50
|
+
def all_jobs_have_been_processed?
|
|
50
51
|
job_count + working_job_count == 0
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
private
|
|
54
55
|
|
|
55
56
|
def authorized?
|
|
56
|
-
HerokuResqueAutoScale::Config.environments.include?
|
|
57
|
+
HerokuResqueAutoScale::Config.environments.include? _environment
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def _environment
|
|
61
|
+
if defined?(Rails)
|
|
62
|
+
Rails.env.to_s
|
|
63
|
+
else
|
|
64
|
+
ENV['ENVIRONMENT'] || 'test'
|
|
65
|
+
end
|
|
57
66
|
end
|
|
58
67
|
|
|
59
68
|
def worker_name
|
|
@@ -94,4 +103,4 @@ module HerokuResqueAutoScale
|
|
|
94
103
|
# and one working job (which is this job)
|
|
95
104
|
Scaler.workers = 0 if Scaler.job_count.zero? && Scaler.working_job_count == 1
|
|
96
105
|
end
|
|
97
|
-
end
|
|
106
|
+
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module HerokuResqueAutoScale
|
|
2
|
-
VERSION = '0.2.
|
|
3
|
-
end
|
|
2
|
+
VERSION = '0.2.1'
|
|
3
|
+
end
|
|
@@ -8,21 +8,8 @@ describe HerokuResqueAutoScale::Config do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
context 'using the supplied config file' do
|
|
11
|
-
it { HerokuResqueAutoScale::Config.thresholds.
|
|
12
|
-
it { HerokuResqueAutoScale::Config.environments.
|
|
13
|
-
it { HerokuResqueAutoScale::Config.worker_name.
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context 'with missing config values' do
|
|
17
|
-
before :each do
|
|
18
|
-
HerokuResqueAutoScale::Config.stub(:config).and_return({})
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it { HerokuResqueAutoScale::Config.thresholds.should be_instance_of Array }
|
|
22
|
-
it { HerokuResqueAutoScale::Config.environments.should eql ['production'] }
|
|
23
|
-
it { HerokuResqueAutoScale::Config.worker_name.should eql 'worker' }
|
|
24
|
-
|
|
11
|
+
it { expect(HerokuResqueAutoScale::Config.thresholds).to be_instance_of Array }
|
|
12
|
+
it { expect(HerokuResqueAutoScale::Config.environments).to eql(['production','staging', 'development']) }
|
|
13
|
+
it { expect(HerokuResqueAutoScale::Config.worker_name).to eql 'worker' }
|
|
25
14
|
end
|
|
26
15
|
end
|
|
27
|
-
|
|
28
|
-
|
|
@@ -3,12 +3,10 @@ require 'spec_helper'
|
|
|
3
3
|
describe HerokuResqueAutoScale::Scaler do
|
|
4
4
|
|
|
5
5
|
context 'when authorised' do
|
|
6
|
-
|
|
7
|
-
before { HerokuResqueAutoScale::Scaler.stub(:authorized?).and_return(true) }
|
|
6
|
+
before { allow(HerokuResqueAutoScale::Scaler).to receive(:authorized?) { true }}
|
|
8
7
|
|
|
9
8
|
context 'with safe mode disabled' do
|
|
10
|
-
|
|
11
|
-
before { HerokuResqueAutoScale::Scaler.stub(:safe_mode?).and_return(false) }
|
|
9
|
+
before { allow(HerokuResqueAutoScale::Scaler).to receive(:safe_mode?) { false }}
|
|
12
10
|
|
|
13
11
|
describe 'get number of workers' do
|
|
14
12
|
before do
|
|
@@ -21,12 +19,12 @@ describe HerokuResqueAutoScale::Scaler do
|
|
|
21
19
|
'type' => 'web',
|
|
22
20
|
'updated_at' => '2012-01-01T12:00:00Z'
|
|
23
21
|
}
|
|
24
|
-
PlatformAPI::Client.
|
|
22
|
+
allow_any_instance_of(PlatformAPI::Client).to receive_message_chain(:formation, :info) { response_hash }
|
|
25
23
|
end
|
|
26
|
-
|
|
27
|
-
it { HerokuResqueAutoScale::Scaler.workers.
|
|
24
|
+
|
|
25
|
+
it { expect(HerokuResqueAutoScale::Scaler.workers).to eql(42) }
|
|
28
26
|
end
|
|
29
|
-
|
|
27
|
+
|
|
30
28
|
describe 'set number of workers' do
|
|
31
29
|
before do
|
|
32
30
|
response_hash = {
|
|
@@ -38,50 +36,49 @@ describe HerokuResqueAutoScale::Scaler do
|
|
|
38
36
|
'type' => 'web',
|
|
39
37
|
'updated_at' => '2012-01-01T12:00:00Z'
|
|
40
38
|
}
|
|
41
|
-
|
|
42
|
-
PlatformAPI::Client.any_instance.stub_chain(:formation, :update).and_return(response_hash)
|
|
39
|
+
allow_any_instance_of(PlatformAPI::Client).to receive_message_chain(:formation, :update) { response_hash }
|
|
43
40
|
end
|
|
44
|
-
|
|
45
|
-
it { HerokuResqueAutoScale::Scaler.send(:workers=, 69).
|
|
41
|
+
|
|
42
|
+
it { expect(HerokuResqueAutoScale::Scaler.send(:workers=, 69)).to be_truthy }
|
|
46
43
|
end
|
|
47
|
-
|
|
44
|
+
|
|
48
45
|
describe 'ask for job and working count' do
|
|
49
|
-
before { Resque.
|
|
50
|
-
|
|
51
|
-
it { HerokuResqueAutoScale::Scaler.job_count.
|
|
52
|
-
it { HerokuResqueAutoScale::Scaler.working_job_count.
|
|
46
|
+
before { allow(Resque).to receive(:info) {{ pending: '16', working: '61' }} }
|
|
47
|
+
|
|
48
|
+
it { expect(HerokuResqueAutoScale::Scaler.job_count).to eql 16 }
|
|
49
|
+
it { expect(HerokuResqueAutoScale::Scaler.working_job_count).to eql 61 }
|
|
53
50
|
end
|
|
54
51
|
end
|
|
55
|
-
|
|
52
|
+
|
|
56
53
|
context 'with safe mode enabled' do
|
|
57
|
-
before { HerokuResqueAutoScale::Scaler.
|
|
54
|
+
before { allow(HerokuResqueAutoScale::Scaler).to receive(:safe_mode?) { true }}
|
|
58
55
|
|
|
59
56
|
context 'when about to scale down' do
|
|
60
|
-
before { HerokuResqueAutoScale::Scaler.
|
|
57
|
+
before { allow(HerokuResqueAutoScale::Scaler).to receive(:setting_this_number_of_workers_will_scale_down?) { true }}
|
|
61
58
|
|
|
62
59
|
context 'when there are some jobs left to process' do
|
|
63
|
-
before { HerokuResqueAutoScale::Scaler.
|
|
60
|
+
before { allow(HerokuResqueAutoScale::Scaler).to receive(:all_jobs_have_been_processed?) { false }}
|
|
64
61
|
|
|
65
|
-
it 'does not trigger the API call' do
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
end
|
|
62
|
+
# it 'does not trigger the API call' do
|
|
63
|
+
# allow_any_instance_of(PlatformAPI::Client).to_not receive(:formation)
|
|
64
|
+
# HerokuResqueAutoScale::Scaler.send(:workers=, '69')
|
|
65
|
+
# end
|
|
69
66
|
end
|
|
70
67
|
|
|
71
68
|
context 'when there are no jobs left to process' do
|
|
72
|
-
before { HerokuResqueAutoScale::Scaler.
|
|
69
|
+
before { allow(HerokuResqueAutoScale::Scaler).to receive(:all_jobs_have_been_processed?) { true }}
|
|
73
70
|
|
|
74
71
|
describe 'should trigger action' do
|
|
75
72
|
it 'does not trigger the API call' do
|
|
76
73
|
mock_client = double(PlatformAPI::Client).as_null_object
|
|
77
|
-
PlatformAPI::Client.
|
|
74
|
+
allow_any_instance_of(PlatformAPI::Client).to receive(:formation) { mock_client }
|
|
78
75
|
HerokuResqueAutoScale::Scaler.send(:workers=, '69')
|
|
79
76
|
end
|
|
80
77
|
end
|
|
81
78
|
end
|
|
82
79
|
end
|
|
83
|
-
|
|
80
|
+
|
|
84
81
|
end
|
|
85
82
|
end
|
|
86
|
-
|
|
87
|
-
end
|
|
83
|
+
|
|
84
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
$:.unshift File.expand_path('..', __FILE__)
|
|
2
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
|
3
|
-
|
|
4
|
-
require 'rspec'
|
|
5
|
-
require 'webmock/rspec'
|
|
6
1
|
require 'heroku-resque-workers-scaler'
|
|
7
|
-
require '
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
|
|
8
4
|
require 'resque'
|
|
9
|
-
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
require 'pry'
|
|
8
|
+
rescue LoadError
|
|
9
|
+
end
|
|
10
10
|
|
|
11
11
|
RSpec.configure do |config|
|
|
12
12
|
config.mock_with :rspec
|
|
@@ -16,4 +16,4 @@ end
|
|
|
16
16
|
# end
|
|
17
17
|
|
|
18
18
|
# RSpec.configuration.before(:each) do
|
|
19
|
-
# end
|
|
19
|
+
# end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: heroku-resque-workers-scaler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mark Quezada
|
|
@@ -9,106 +9,92 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: resque
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
requirements:
|
|
18
|
-
- - "
|
|
18
|
+
- - "~>"
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 1.25.2
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
|
-
- - "
|
|
25
|
+
- - "~>"
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 1.25.2
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: platform-api
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
|
-
- - "
|
|
32
|
+
- - "~>"
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version:
|
|
34
|
+
version: 0.2.0
|
|
35
35
|
type: :runtime
|
|
36
36
|
prerelease: false
|
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
|
-
- - "
|
|
39
|
+
- - "~>"
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version:
|
|
42
|
-
- !ruby/object:Gem::Dependency
|
|
43
|
-
name: rails
|
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
|
45
|
-
requirements:
|
|
46
|
-
- - ">="
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: '0'
|
|
49
|
-
type: :development
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - ">="
|
|
54
|
-
- !ruby/object:Gem::Version
|
|
55
|
-
version: '0'
|
|
41
|
+
version: 0.2.0
|
|
56
42
|
- !ruby/object:Gem::Dependency
|
|
57
43
|
name: rspec
|
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
|
59
45
|
requirements:
|
|
60
|
-
- - "
|
|
46
|
+
- - "~>"
|
|
61
47
|
- !ruby/object:Gem::Version
|
|
62
|
-
version:
|
|
48
|
+
version: 3.1.0
|
|
63
49
|
type: :development
|
|
64
50
|
prerelease: false
|
|
65
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
52
|
requirements:
|
|
67
|
-
- - "
|
|
53
|
+
- - "~>"
|
|
68
54
|
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
55
|
+
version: 3.1.0
|
|
70
56
|
- !ruby/object:Gem::Dependency
|
|
71
57
|
name: webmock
|
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
|
73
59
|
requirements:
|
|
74
|
-
- - "
|
|
60
|
+
- - "~>"
|
|
75
61
|
- !ruby/object:Gem::Version
|
|
76
|
-
version:
|
|
62
|
+
version: 1.18.0
|
|
77
63
|
type: :development
|
|
78
64
|
prerelease: false
|
|
79
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
80
66
|
requirements:
|
|
81
|
-
- - "
|
|
67
|
+
- - "~>"
|
|
82
68
|
- !ruby/object:Gem::Version
|
|
83
|
-
version:
|
|
69
|
+
version: 1.18.0
|
|
84
70
|
- !ruby/object:Gem::Dependency
|
|
85
71
|
name: rake
|
|
86
72
|
requirement: !ruby/object:Gem::Requirement
|
|
87
73
|
requirements:
|
|
88
|
-
- - "
|
|
74
|
+
- - "~>"
|
|
89
75
|
- !ruby/object:Gem::Version
|
|
90
|
-
version:
|
|
76
|
+
version: 10.3.2
|
|
91
77
|
type: :development
|
|
92
78
|
prerelease: false
|
|
93
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
94
80
|
requirements:
|
|
95
|
-
- - "
|
|
81
|
+
- - "~>"
|
|
96
82
|
- !ruby/object:Gem::Version
|
|
97
|
-
version:
|
|
83
|
+
version: 10.3.2
|
|
98
84
|
- !ruby/object:Gem::Dependency
|
|
99
85
|
name: psych
|
|
100
86
|
requirement: !ruby/object:Gem::Requirement
|
|
101
87
|
requirements:
|
|
102
|
-
- - "
|
|
88
|
+
- - "~>"
|
|
103
89
|
- !ruby/object:Gem::Version
|
|
104
|
-
version:
|
|
90
|
+
version: 2.0.6
|
|
105
91
|
type: :development
|
|
106
92
|
prerelease: false
|
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
|
108
94
|
requirements:
|
|
109
|
-
- - "
|
|
95
|
+
- - "~>"
|
|
110
96
|
- !ruby/object:Gem::Version
|
|
111
|
-
version:
|
|
97
|
+
version: 2.0.6
|
|
112
98
|
description: Auto scale your resque workers on Heroku.
|
|
113
99
|
email:
|
|
114
100
|
- mark@mirthlab.com
|
|
@@ -127,16 +113,16 @@ files:
|
|
|
127
113
|
- LICENSE.txt
|
|
128
114
|
- README.md
|
|
129
115
|
- Rakefile
|
|
116
|
+
- config/scaler_config.yml
|
|
130
117
|
- heroku-resque-workers-scaler.gemspec
|
|
131
118
|
- lib/heroku-resque-workers-scaler.rb
|
|
132
119
|
- lib/heroku-resque-workers-scaler/config.rb
|
|
133
120
|
- lib/heroku-resque-workers-scaler/scaler.rb
|
|
134
121
|
- lib/heroku-resque-workers-scaler/version.rb
|
|
135
|
-
- scaler_config.yml
|
|
136
122
|
- spec/heroku-resque-workers-scaler/config_spec.rb
|
|
137
123
|
- spec/heroku-resque-workers-scaler/scaler_spec.rb
|
|
138
124
|
- spec/spec_helper.rb
|
|
139
|
-
homepage:
|
|
125
|
+
homepage: https://github.com/joel/heroku-resque-workers-scaler
|
|
140
126
|
licenses:
|
|
141
127
|
- MIT
|
|
142
128
|
metadata: {}
|