heroku-resque-workers-scaler 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +42 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +40 -0
- data/COMMANDS +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +129 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +67 -0
- data/Rakefile +7 -0
- data/heroku-resque-workers-scaler.gemspec +26 -0
- data/lib/heroku-resque-workers-scaler.rb +3 -0
- data/lib/heroku-resque-workers-scaler/config.rb +42 -0
- data/lib/heroku-resque-workers-scaler/scaler.rb +84 -0
- data/lib/heroku-resque-workers-scaler/version.rb +3 -0
- data/scaler_config.yml +14 -0
- data/spec/heroku-resque-workers-scaler/config_spec.rb +8 -0
- data/spec/heroku-resque-workers-scaler/scaler_spec.rb +71 -0
- data/spec/spec_helper.rb +19 -0
- metadata +166 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
#
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
#
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
#
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p194@scaler --create
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Changelog VERSION = '0.1.6'
|
2
|
+
|
3
|
+
* Changes name from heroku-resque-auto-scale to heroku-resque-workers-scaler
|
4
|
+
|
5
|
+
# Changelog VERSION = '0.1.5'
|
6
|
+
|
7
|
+
* Add safe mode for Heroku
|
8
|
+
|
9
|
+
# Changelog VERSION = '0.1.4'
|
10
|
+
|
11
|
+
* Add protection execution for determinate environments, defaults 'production'
|
12
|
+
* Add possibilité of override config on your project
|
13
|
+
|
14
|
+
# Changelog VERSION = '0.1.3'
|
15
|
+
|
16
|
+
## Principals changes :
|
17
|
+
|
18
|
+
* Switch from Jeweler Gem generator to simple Bundler gem generator
|
19
|
+
* Switch to Rspec from TestUnit
|
20
|
+
* Switch to HerokuAPI Gem instead of Heroku Client Gem
|
21
|
+
* Configuration into yaml file (optionnal)
|
22
|
+
|
23
|
+
### Requirements :
|
24
|
+
|
25
|
+
You need to defined two vars for your heroku app :
|
26
|
+
|
27
|
+
Go to your https://api.heroku.com/account for retreive your API Key
|
28
|
+
|
29
|
+
heroku config:add HEROKU_API_KEY=your_api_key -a your_app_name
|
30
|
+
heroku config:add HEROKU_APP_NAME=your_app_name -a your_app_name
|
31
|
+
|
32
|
+
### Configuration
|
33
|
+
|
34
|
+
You can changes thresholds into scaler_config.yml (It's totally optional)
|
35
|
+
|
36
|
+
### Test
|
37
|
+
|
38
|
+
You can test with this command line :
|
39
|
+
|
40
|
+
HEROKU_API_KEY=your_api_key HEROKU_APP_NAME=your_app_name *** bundle exec *** rake spec
|
data/COMMANDS
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
bundle && HEROKU_API_KEY=your_api_key HEROKU_APP_NAME=your_app_name bundle exec rake spec
|
2
|
+
gem build heroku-resque-workers-scaler.gemspec
|
3
|
+
git tag -a v0.1.6 -m 'version 0.1.6'
|
4
|
+
git push --tags
|
5
|
+
gem push heroku-resque-workers-scaler-0.1.6.gem
|
6
|
+
git push origin master
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
heroku-resque-workers-scaler (0.1.5)
|
5
|
+
heroku-api
|
6
|
+
resque
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (3.2.8)
|
12
|
+
actionpack (= 3.2.8)
|
13
|
+
mail (~> 2.4.4)
|
14
|
+
actionpack (3.2.8)
|
15
|
+
activemodel (= 3.2.8)
|
16
|
+
activesupport (= 3.2.8)
|
17
|
+
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.1.3)
|
24
|
+
activemodel (3.2.8)
|
25
|
+
activesupport (= 3.2.8)
|
26
|
+
builder (~> 3.0.0)
|
27
|
+
activerecord (3.2.8)
|
28
|
+
activemodel (= 3.2.8)
|
29
|
+
activesupport (= 3.2.8)
|
30
|
+
arel (~> 3.0.2)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.2.8)
|
33
|
+
activemodel (= 3.2.8)
|
34
|
+
activesupport (= 3.2.8)
|
35
|
+
activesupport (3.2.8)
|
36
|
+
i18n (~> 0.6)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
addressable (2.3.2)
|
39
|
+
arel (3.0.2)
|
40
|
+
builder (3.0.4)
|
41
|
+
crack (0.3.1)
|
42
|
+
diff-lcs (1.1.3)
|
43
|
+
erubis (2.7.0)
|
44
|
+
excon (0.16.7)
|
45
|
+
heroku-api (0.3.5)
|
46
|
+
excon (~> 0.16.1)
|
47
|
+
hike (1.2.1)
|
48
|
+
i18n (0.6.1)
|
49
|
+
journey (1.0.4)
|
50
|
+
json (1.7.5)
|
51
|
+
mail (2.4.4)
|
52
|
+
i18n (>= 0.4.0)
|
53
|
+
mime-types (~> 1.16)
|
54
|
+
treetop (~> 1.4.8)
|
55
|
+
mime-types (1.19)
|
56
|
+
multi_json (1.3.6)
|
57
|
+
polyglot (0.3.3)
|
58
|
+
rack (1.4.1)
|
59
|
+
rack-cache (1.2)
|
60
|
+
rack (>= 0.4)
|
61
|
+
rack-protection (1.2.0)
|
62
|
+
rack
|
63
|
+
rack-ssl (1.3.2)
|
64
|
+
rack
|
65
|
+
rack-test (0.6.2)
|
66
|
+
rack (>= 1.0)
|
67
|
+
rails (3.2.8)
|
68
|
+
actionmailer (= 3.2.8)
|
69
|
+
actionpack (= 3.2.8)
|
70
|
+
activerecord (= 3.2.8)
|
71
|
+
activeresource (= 3.2.8)
|
72
|
+
activesupport (= 3.2.8)
|
73
|
+
bundler (~> 1.0)
|
74
|
+
railties (= 3.2.8)
|
75
|
+
railties (3.2.8)
|
76
|
+
actionpack (= 3.2.8)
|
77
|
+
activesupport (= 3.2.8)
|
78
|
+
rack-ssl (~> 1.3.2)
|
79
|
+
rake (>= 0.8.7)
|
80
|
+
rdoc (~> 3.4)
|
81
|
+
thor (>= 0.14.6, < 2.0)
|
82
|
+
rake (0.8.7)
|
83
|
+
rdoc (3.12)
|
84
|
+
json (~> 1.4)
|
85
|
+
redis (3.0.2)
|
86
|
+
redis-namespace (1.2.1)
|
87
|
+
redis (~> 3.0.0)
|
88
|
+
resque (1.23.0)
|
89
|
+
multi_json (~> 1.0)
|
90
|
+
redis-namespace (~> 1.0)
|
91
|
+
sinatra (>= 0.9.2)
|
92
|
+
vegas (~> 0.1.2)
|
93
|
+
rspec (2.11.0)
|
94
|
+
rspec-core (~> 2.11.0)
|
95
|
+
rspec-expectations (~> 2.11.0)
|
96
|
+
rspec-mocks (~> 2.11.0)
|
97
|
+
rspec-core (2.11.1)
|
98
|
+
rspec-expectations (2.11.3)
|
99
|
+
diff-lcs (~> 1.1.3)
|
100
|
+
rspec-mocks (2.11.3)
|
101
|
+
sinatra (1.3.3)
|
102
|
+
rack (~> 1.3, >= 1.3.6)
|
103
|
+
rack-protection (~> 1.2)
|
104
|
+
tilt (~> 1.3, >= 1.3.3)
|
105
|
+
sprockets (2.1.3)
|
106
|
+
hike (~> 1.2)
|
107
|
+
rack (~> 1.0)
|
108
|
+
tilt (~> 1.1, != 1.3.0)
|
109
|
+
thor (0.16.0)
|
110
|
+
tilt (1.3.3)
|
111
|
+
treetop (1.4.11)
|
112
|
+
polyglot
|
113
|
+
polyglot (>= 0.3.1)
|
114
|
+
tzinfo (0.3.33)
|
115
|
+
vegas (0.1.11)
|
116
|
+
rack (>= 1.0.0)
|
117
|
+
webmock (1.8.11)
|
118
|
+
addressable (>= 2.2.7)
|
119
|
+
crack (>= 0.1.7)
|
120
|
+
|
121
|
+
PLATFORMS
|
122
|
+
ruby
|
123
|
+
|
124
|
+
DEPENDENCIES
|
125
|
+
heroku-resque-workers-scaler!
|
126
|
+
rails
|
127
|
+
rake
|
128
|
+
rspec
|
129
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Mark Quezada
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# heroku-resque-workers-scaler
|
2
|
+
|
3
|
+
Auto scale your resque workers on Heroku. Original code by darkhelmet:
|
4
|
+
|
5
|
+
* http://blog.darkhax.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
|
6
|
+
* https://gist.github.com/501160
|
7
|
+
|
8
|
+
Modify by joel => https://github.com/joel
|
9
|
+
|
10
|
+
On fork => https://github.com/joel/heroku-resque-workers-scaler
|
11
|
+
|
12
|
+
### Principals changes :
|
13
|
+
|
14
|
+
* I've switched Jeweler Gem generator to simpel Bundler gem generator
|
15
|
+
* I've switched to Rspec from TestUnit
|
16
|
+
* I've switched to HerokuAPI Gem instead of Heroku Client Gem
|
17
|
+
* Add safe mode for heroku
|
18
|
+
|
19
|
+
### Configuration :
|
20
|
+
|
21
|
+
You need to defined two vars for your heroku :
|
22
|
+
|
23
|
+
Go to your https://api.heroku.com/account
|
24
|
+
heroku config:add HEROKU_API_KEY=your_api_key -a your_app_name
|
25
|
+
heroku config:add HEROKU_APP_NAME=your_app_name -a your_app_name
|
26
|
+
|
27
|
+
You can test when executed this :
|
28
|
+
```
|
29
|
+
HEROKU_API_KEY=your_api_key HEROKU_APP_NAME=your_app_name *** bundle exec *** rake spec
|
30
|
+
```
|
31
|
+
You can changes thresholds and environments of execution into scaler_config.yml or on your project on config/scaler_config.yml
|
32
|
+
|
33
|
+
I just bundled it into a gem for easy inclusion into other projects.
|
34
|
+
|
35
|
+
#### Usage
|
36
|
+
|
37
|
+
Once the gem is installed, simply extend your job class as follows:
|
38
|
+
```
|
39
|
+
class ScalingJob
|
40
|
+
extend HerokuResqueAutoScale
|
41
|
+
|
42
|
+
def self.perform
|
43
|
+
# Do something long running
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
#### Active safe mode
|
48
|
+
|
49
|
+
When you ask heroku for scale down workers, heroku send SIGTERM and wait 4 secondes then send SIGKILL, but the worker catch signals can be currently work :( It's bad but Heroku not provide API for manage this case today, you can look arround this [official article](https://devcenter.heroku.com/articles/queuing-ruby-resque#job-termination) but in this gem if you defined var ENV['SAFE_MODE'] :
|
50
|
+
```
|
51
|
+
heroku config:add SAFE_MODE=true -a your_app_name
|
52
|
+
```
|
53
|
+
## Contributing to heroku-resque-workers-scaler
|
54
|
+
|
55
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
56
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
57
|
+
* Fork the project
|
58
|
+
* Start a feature/bugfix branch
|
59
|
+
* Commit and push until you are happy with your contribution
|
60
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
61
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
62
|
+
|
63
|
+
== Copyright
|
64
|
+
|
65
|
+
Copyright (c) 2010 Mark Quezada. See LICENSE.txt for
|
66
|
+
further details.
|
67
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/heroku-resque-workers-scaler/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Mark Quezada', 'Joel AZEMAR']
|
6
|
+
gem.email = ['mark@mirthlab.com', 'joel.azemar@gmail.com']
|
7
|
+
gem.description = %q{Auto scale your resque workers on Heroku.}
|
8
|
+
gem.summary = %q{Simple helper for Rails App configuration}
|
9
|
+
gem.homepage = 'http://github.com/mirthlab/heroku-resque-workers-scaler'
|
10
|
+
# gem.homepage = 'https://github.com/joel/heroku-resque-workers-scaler'
|
11
|
+
gem.licenses = [ 'MIT' ]
|
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
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'resque'
|
20
|
+
gem.add_runtime_dependency 'heroku-api'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rails'
|
23
|
+
gem.add_development_dependency 'rspec'
|
24
|
+
gem.add_development_dependency 'webmock'
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module HerokuResqueAutoScale
|
2
|
+
module Config
|
3
|
+
extend self
|
4
|
+
|
5
|
+
CONFIG_FILE_NAME = 'scaler_config.yml'
|
6
|
+
|
7
|
+
def thresholds
|
8
|
+
@thresholds ||= begin
|
9
|
+
if config_file?
|
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
|
15
|
+
end
|
16
|
+
|
17
|
+
def environments
|
18
|
+
@environments ||= begin
|
19
|
+
if config_file?
|
20
|
+
config['environments']
|
21
|
+
else
|
22
|
+
[ 'production' ]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def config_file?
|
30
|
+
@config_file ||= override? || File.exists?(CONFIG_FILE_NAME)
|
31
|
+
end
|
32
|
+
|
33
|
+
def config
|
34
|
+
@config ||= override? ? YAML.load_file(Rails.root.join("config/#{CONFIG_FILE_NAME}").to_s) : YAML.load_file(CONFIG_FILE_NAME)
|
35
|
+
end
|
36
|
+
|
37
|
+
def override?
|
38
|
+
File.exists?(Rails.root.join("config/#{CONFIG_FILE_NAME}").to_s) rescue false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'heroku-api'
|
2
|
+
|
3
|
+
module HerokuResqueAutoScale
|
4
|
+
module Scaler
|
5
|
+
|
6
|
+
class << self
|
7
|
+
@@heroku = Heroku::API.new(api_key: ENV['HEROKU_API_KEY'])
|
8
|
+
|
9
|
+
def workers
|
10
|
+
return nil unless authorised?
|
11
|
+
@@heroku.get_app(ENV['HEROKU_APP_NAME']).body['workers'].to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def workers=(qty)
|
15
|
+
return unless authorised?
|
16
|
+
if safe_mode? and down? qty
|
17
|
+
return unless safer?
|
18
|
+
end
|
19
|
+
@@heroku.post_ps_scale(ENV['HEROKU_APP_NAME'], 'worker', qty.to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def job_count
|
23
|
+
Resque.info[:pending].to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def working_job_count
|
27
|
+
Resque.info[:working].to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def down? qty
|
33
|
+
qty < workers
|
34
|
+
end
|
35
|
+
|
36
|
+
def safe_mode?
|
37
|
+
ENV['SAFE_MODE'] and ENV['SAFE_MODE'] == 'true'
|
38
|
+
end
|
39
|
+
|
40
|
+
def safer?
|
41
|
+
job_count + working_job_count == 0
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def authorised?
|
47
|
+
HerokuResqueAutoScale::Config.thresholds.include? Rails.env.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def after_perform_scale_down(*args)
|
54
|
+
scale_down
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_failure_scale_down(exception, *args)
|
58
|
+
scale_down
|
59
|
+
end
|
60
|
+
|
61
|
+
def after_enqueue_scale_up(*args)
|
62
|
+
HerokuResqueAutoScale::Config.thresholds.reverse_each do |scale_info|
|
63
|
+
# Run backwards so it gets set to the highest value first
|
64
|
+
# Otherwise if there were 70 jobs, it would get set to 1, then 2, then 3, etc
|
65
|
+
|
66
|
+
# If we have a job count greater than or equal to the job limit for this scale info
|
67
|
+
if Scaler.job_count >= scale_info[:job_count]
|
68
|
+
# Set the number of workers unless they are already set to a level we want. Don't scale down here!
|
69
|
+
if Scaler.workers <= scale_info[:workers]
|
70
|
+
Scaler.workers = scale_info[:workers]
|
71
|
+
end
|
72
|
+
break # We've set or ensured that the worker count is high enough
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def scale_down
|
80
|
+
# Nothing fancy, just shut everything down if we have no pending jobs
|
81
|
+
# and one working job (which is this job)
|
82
|
+
Scaler.workers = 0 if Scaler.job_count.zero? && Scaler.working_job_count == 1
|
83
|
+
end
|
84
|
+
end
|
data/scaler_config.yml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# HEROKU_API_KEY=your_api_key HEROKU_APP_NAME=your_app_name bundle exec rake spec
|
4
|
+
describe HerokuResqueAutoScale::Scaler do
|
5
|
+
|
6
|
+
context 'authorised' do
|
7
|
+
before { HerokuResqueAutoScale::Scaler.stub authorised?: true }
|
8
|
+
context 'unsafe mode' do
|
9
|
+
before { HerokuResqueAutoScale::Scaler.stub safe_mode?: false }
|
10
|
+
|
11
|
+
context 'get number of workers' do
|
12
|
+
before do
|
13
|
+
stub_request(:get, "https://api.heroku.com/apps/your_app_name").
|
14
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip', 'Authorization'=>'Basic OnlvdXJfYXBpX2tleQ==', \
|
15
|
+
'Host'=>'api.heroku.com:443', 'User-Agent'=>'heroku-rb/0.3.5', 'X-Ruby-Platform'=>'x86_64-darwin12.2.0', 'X-Ruby-Version'=>'1.9.3'}).
|
16
|
+
to_return(:status => 200, :body => JSON.generate({ workers: '42' }), :headers => {})
|
17
|
+
end
|
18
|
+
|
19
|
+
it { HerokuResqueAutoScale::Scaler.workers.should eql 42 }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'set number of workers' do
|
23
|
+
before do
|
24
|
+
stub_request(:post, "https://api.heroku.com/apps/your_app_name/ps/scale?qty=69&type=worker").
|
25
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip', 'Authorization'=>'Basic OnlvdXJfYXBpX2tleQ==', \
|
26
|
+
'Host'=>'api.heroku.com:443', 'User-Agent'=>'heroku-rb/0.3.5', 'X-Ruby-Platform'=>'x86_64-darwin12.2.0', 'X-Ruby-Version'=>'1.9.3'}).
|
27
|
+
to_return(:status => 200, :body => "", :headers => {})
|
28
|
+
end
|
29
|
+
|
30
|
+
it { HerokuResqueAutoScale::Scaler.send(:workers=, '69') }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'ask for job and working count' do
|
34
|
+
before { Resque.stub(info: { pending: '16', working: '61' }) }
|
35
|
+
|
36
|
+
it { HerokuResqueAutoScale::Scaler.job_count.should eql 16 }
|
37
|
+
it { HerokuResqueAutoScale::Scaler.working_job_count.should eql 61 }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'on safe mode' do
|
42
|
+
before { HerokuResqueAutoScale::Scaler.stub safe_mode?: true }
|
43
|
+
|
44
|
+
context 'try unsafe action' do
|
45
|
+
before { HerokuResqueAutoScale::Scaler.stub safer?: false, down?: true }
|
46
|
+
|
47
|
+
describe 'should not trigger action' do
|
48
|
+
|
49
|
+
it { HerokuResqueAutoScale::Scaler.send(:workers=, '69').should be_nil } # Webmock do nothing here
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'try safe action' do
|
54
|
+
before { HerokuResqueAutoScale::Scaler.stub safer?: true, down?: true }
|
55
|
+
|
56
|
+
describe 'should not trigger action' do
|
57
|
+
before do
|
58
|
+
stub_request(:post, "https://api.heroku.com/apps/your_app_name/ps/scale?qty=69&type=worker").
|
59
|
+
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip', 'Authorization'=>'Basic OnlvdXJfYXBpX2tleQ==', \
|
60
|
+
'Host'=>'api.heroku.com:443', 'User-Agent'=>'heroku-rb/0.3.5', 'X-Ruby-Platform'=>'x86_64-darwin12.2.0', 'X-Ruby-Version'=>'1.9.3'}).
|
61
|
+
to_return(:status => 200, :body => "", :headers => {})
|
62
|
+
end
|
63
|
+
|
64
|
+
it { HerokuResqueAutoScale::Scaler.send(:workers=, '69') }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'heroku-resque-workers-scaler'
|
7
|
+
require 'json'
|
8
|
+
require 'resque'
|
9
|
+
require 'rails'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.mock_with :rspec
|
13
|
+
end
|
14
|
+
|
15
|
+
# RSpec.configuration.after(:each) do
|
16
|
+
# end
|
17
|
+
|
18
|
+
# RSpec.configuration.before(:each) do
|
19
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku-resque-workers-scaler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Quezada
|
9
|
+
- Joel AZEMAR
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: resque
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: heroku-api
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: webmock
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rake
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Auto scale your resque workers on Heroku.
|
112
|
+
email:
|
113
|
+
- mark@mirthlab.com
|
114
|
+
- joel.azemar@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .document
|
120
|
+
- .gitignore
|
121
|
+
- .rvmrc
|
122
|
+
- CHANGELOG.md
|
123
|
+
- COMMANDS
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- heroku-resque-workers-scaler.gemspec
|
130
|
+
- lib/heroku-resque-workers-scaler.rb
|
131
|
+
- lib/heroku-resque-workers-scaler/config.rb
|
132
|
+
- lib/heroku-resque-workers-scaler/scaler.rb
|
133
|
+
- lib/heroku-resque-workers-scaler/version.rb
|
134
|
+
- scaler_config.yml
|
135
|
+
- spec/heroku-resque-workers-scaler/config_spec.rb
|
136
|
+
- spec/heroku-resque-workers-scaler/scaler_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
homepage: http://github.com/mirthlab/heroku-resque-workers-scaler
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ! '>='
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.8.24
|
160
|
+
signing_key:
|
161
|
+
specification_version: 3
|
162
|
+
summary: Simple helper for Rails App configuration
|
163
|
+
test_files:
|
164
|
+
- spec/heroku-resque-workers-scaler/config_spec.rb
|
165
|
+
- spec/heroku-resque-workers-scaler/scaler_spec.rb
|
166
|
+
- spec/spec_helper.rb
|