heroku-scaler 0.1.11 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d9da01ef9c047bf8ba94ac959180e4c853c7937
4
- data.tar.gz: 92b23067c35522391e6401ecdcdedebfbf38b2b9
3
+ metadata.gz: e8b289781885499b26a6a5d92ddcdff1bdd8e448
4
+ data.tar.gz: 276acb502af5724c36f861b34aaa46f1a3ee2789
5
5
  SHA512:
6
- metadata.gz: 829cb9be362a94790490a5f67234eaae5c900ce0ff173e075b5cdaa8cf55883b1d5c535a35bed42746e18340f5537fca07a00b8f4d6e04820352191b2e83b298
7
- data.tar.gz: 70cff84b5a1ed2b454a63c9c14844bda245667a4bc9796af54eefe782e74d504b89ab5ccade4fd967d907b7d8d8f9156a713a0b45d7bad73ca051128e1005e0a
6
+ metadata.gz: 7790e5d9c3f1ace9c7d9b73a8ce9d515c8a740c7d7868875bd4b06f8cb50885662e136483bd29a44b38505dea654648bb21411fe3370f331723dba9927651384
7
+ data.tar.gz: 8c6b48c9e456ada4d33520c1b3adc32b081bca1be49a79e20019577ba4f2c2407f6c88bd2e35c8255461c76082da4bc6043471cac863f7351caedf8de8f5bff1
data/.gitignore CHANGED
@@ -27,9 +27,9 @@ build/
27
27
 
28
28
  # for a library or gem, you might want to ignore these files since the code is
29
29
  # intended to run in multiple environments; otherwise, check them in:
30
- # Gemfile.lock
31
- # .ruby-version
32
- # .ruby-gemset
30
+ Gemfile.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
33
 
34
34
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
35
  .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/README.md CHANGED
@@ -1 +1,98 @@
1
- # heroku-scaler
1
+ # Heroku Scaler
2
+
3
+ The Heroku Scaler gem allows for free scaling of Heroku web dynos.
4
+ It exposes 3 simple rake tasks that can be called from the free [Heroku
5
+ Scheduler](https://elements.heroku.com/addons/scheduler).
6
+
7
+ This is perfect for applications that see heavy use during known times of the day or week. For example, we have some customers with business systems that see 99.9% of their traffic during regular business hours on the weekdays. Since Heroku charges for dynos based on the number of seconds the dynos are running, scaling down application dynos during off-peak times can mean big savings. Running your larger dyno setup during the 25% of normal business hours can save a bundle! There are other tools that purport to do this but they often charge money and have, in our experience, been poorly supported.
8
+
9
+ ## Commands
10
+
11
+ The Heroku Scaler gem exposes three rake commands when added to a Rails application.
12
+
13
+ The below command will scale your application web dynos to the SCALE_BIG_DYNO_COUNT and SCALE_BIG_DYNO_TYPE.
14
+
15
+ `rake heroku_scale:web:up`
16
+
17
+ The below command will scale your application web dynos to the SCALE_SMALL_DYNO_COUNT and SCALE_SMALL_DYNO_TYPE.
18
+
19
+ `rake heroku_scale:web:down`
20
+
21
+ The below command will scale your application web dynos to the SCALE_BIG_DYNO_COUNT and SCALE_BIG_DYNO_TYPE if it is a weekday.
22
+
23
+ `rake heroku_scale:web:up_if_weekday`
24
+
25
+ ## Configuration options
26
+
27
+ All of these configuration options can be set through the Heroku application configuration (`heroku config:set SOME_SETTING=some_value`)
28
+
29
+ | Setting | Default | |
30
+ | --- | --- | --- |
31
+ | SCALE_APP_NAME| | your Heroku application name |
32
+ | SCALE_BIG_DYNO_COUNT | 3 | the number of scaled up dynos |
33
+ | SCALE_BIG_DYNO_TYPE | Standard-2X | the type of scaled up dyno |
34
+ | SCALE_OAUTH_TOKEN | | Heroku account auth token |
35
+ | SCALE_SMALL_DYNO_COUNT | 1 | the number of scaled down dynos |
36
+ | SCALE_SMALL_DYNO_TYPE | Standard=1X | the type of scaled down dyno |
37
+
38
+ ## Installation
39
+
40
+ 1. Add Heroku Scaler to your Rails application.
41
+
42
+ add the gem to your `Gemfile`
43
+
44
+ `gem "heroku_scaler"`
45
+
46
+ User Bundler to install the gem in your project
47
+
48
+ ```shell
49
+ bundle
50
+ ```
51
+
52
+ 2. Generate an
53
+ 2. Add settings to your Heroku configuration.
54
+
55
+ Assuming a Heroku application named "my-cool-app":
56
+
57
+ ```shell
58
+ heroku config:set SCALE_APP_NAME=my-cool-app
59
+ heroku config:set SCALE_BIG_DYNO_COUNT=2
60
+ heroku config:set SCALE_BIG_DYNO_TYPE=Standard-1X
61
+ heroku config:set SCALE_OAUTH_TOKEN=<some_token_here>
62
+ heroku config:set SCALE_SMALL_DYNO_COUNT=2
63
+ heroku config:set SCALE_SMALL_DYNO_TYPE=Standard-2X
64
+ ```
65
+ 3. Install the [Heroku
66
+ Scheduler](https://elements.heroku.com/addons/scheduler) into your Heroku application.
67
+
68
+ 4. Add scheduled events at the times you wish for your application to scale up or down.
69
+
70
+ ## Running tests
71
+
72
+ ```shell
73
+ bundle
74
+ bundle exec rspec spec
75
+ ```
76
+
77
+ ## Left to do
78
+
79
+ 1. Add support for time zones so the `heroku_scale:web:up_if_weekday` task behaves as expected in all time zones.
80
+ 2. Add support for scaling Heroku workers
81
+
82
+ ## Contributing
83
+
84
+ Please feel free to submit pull requests or issues. Support for more servers would be neat.
85
+
86
+ 1. Fork it
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create new Pull Request
91
+
92
+ ## About Foraker Labs
93
+
94
+ [![Foraker Logo](http://assets.foraker.com/attribution_logo.png)](https://www.foraker.com/)
95
+
96
+ [Foraker Labs](https://www.foraker.com/) builds exciting web and mobile apps in Boulder, CO. Our work powers a wide variety of businesses with many different needs. We love open source software, and we're proud to contribute where we can. Interested to learn more? [Contact us today](https://www.foraker.com/contact-us).
97
+
98
+ This project is maintained by Foraker Labs. The names and logos of Foraker Labs are fully owned and copyright Foraker Design, LLC.
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ['lib']
18
18
 
19
19
  s.add_dependency 'platform-api', '~> 0'
20
+
21
+ s.add_development_dependency "rspec", '~> 3'
20
22
  end
@@ -0,0 +1,33 @@
1
+ module HerokuScaler
2
+ class Config
3
+ attr_reader :settings
4
+
5
+ def initialize(settings=ENV)
6
+ @settings=settings
7
+ end
8
+
9
+ def app_name
10
+ settings["SCALE_APP_NAME"]
11
+ end
12
+
13
+ def big_dyno_type
14
+ settings["SCALE_BIG_DYNO_TYPE"] || "Standard-2X"
15
+ end
16
+
17
+ def big_dyno_count
18
+ settings["SCALE_BIG_DYNO_COUNT"] || 3
19
+ end
20
+
21
+ def small_dyno_type
22
+ settings["SCALE_SMALL_DYNO_TYPE"] || "Standard-1X"
23
+ end
24
+
25
+ def small_dyno_count
26
+ settings["SCALE_SMALL_DYNO_COUNT"] || 1
27
+ end
28
+
29
+ def auth_token
30
+ settings["SCALE_OAUTH_TOKEN"]
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module HerokuScaler
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.13'
3
3
  end
@@ -0,0 +1,49 @@
1
+ module HerokuScaler
2
+ class WebScale
3
+ extend Forwardable
4
+
5
+ def initialize(config=Config.new, platform_api=PlatformAPI)
6
+ @config = config
7
+ @platform_api = platform_api
8
+ end
9
+
10
+ def up!
11
+ web_scale(big_dyno_type, big_dyno_count)
12
+ end
13
+
14
+ def up_if_weekday!
15
+ up! if weekday?
16
+ end
17
+
18
+ def down!
19
+ web_scale(small_dyno_type, small_dyno_count)
20
+ end
21
+
22
+ def weekday?
23
+ (1..5).include?(Date.today.cwday)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :config, :platform_api
29
+
30
+ def_delegators :config,
31
+ :app_name,
32
+ :big_dyno_type,
33
+ :big_dyno_count,
34
+ :small_dyno_type,
35
+ :small_dyno_count,
36
+ :auth_token
37
+
38
+ def web_scale(dyno_type, dyno_count)
39
+ heroku.formation.update(app_name, 'web', {
40
+ size: dyno_type,
41
+ quantity: dyno_count
42
+ })
43
+ end
44
+
45
+ def heroku
46
+ @heroku ||= platform_api.connect_oauth(auth_token)
47
+ end
48
+ end
49
+ end
@@ -2,55 +2,17 @@ namespace :heroku_scale do
2
2
  namespace :web do
3
3
  desc "Scale heroku web dynos up if it is a weekday"
4
4
  task :up_if_weekday do
5
- Rake::Task['heroku_scale:web:up'].invoke if weekday?
5
+ HerokuScaler::WebScale.new.up_if_weekday!
6
6
  end
7
7
 
8
8
  desc "Scale heroku web dynos up"
9
9
  task :up do
10
- heroku.formation.update(app_name, 'web', {
11
- "size" => big_dyno_type,
12
- "quantity" => big_dyno_count
13
- })
10
+ HerokuScaler::WebScale.new.up!
14
11
  end
15
12
 
16
13
  desc "Scale heroku web dynos down"
17
14
  task :down do
18
- heroku.formation.update(app_name, 'web', {
19
- "size" => small_dyno_type,
20
- "quantity" => small_dyno_count
21
- })
15
+ HerokuScaler::WebScale.new.down!
22
16
  end
23
17
  end
24
18
  end
25
-
26
- def heroku
27
- @heroku ||= PlatformAPI.connect_oauth(oauth_token)
28
- end
29
-
30
- def oauth_token
31
- ENV["SCALE_OAUTH_TOKEN"]
32
- end
33
-
34
- def app_name
35
- ENV["SCALE_APP_NAME"] || 'ids-production'
36
- end
37
-
38
- def big_dyno_type
39
- ENV["SCALE_BIG_DYNO_TYPE"] || "Performance"
40
- end
41
-
42
- def big_dyno_count
43
- ENV["SCALE_BIG_DYNO_COUNT"] || 3
44
- end
45
-
46
- def small_dyno_type
47
- ENV["SCALE_SMALL_DYNO_TYPE"] || "Standard-2X"
48
- end
49
-
50
- def small_dyno_count
51
- ENV["SCALE_SMALL_DYNO_COUNT"] || 1
52
- end
53
-
54
- def weekday?
55
- (1..5).include?(Date.today.cwday)
56
- end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'heroku-scaler/config'
3
+
4
+ module HerokuScaler
5
+ describe Config do
6
+ let(:config) { HerokuScaler::Config.new({}) }
7
+
8
+ describe "#big_dyno_type" do
9
+ it "has a default" do
10
+ expect(config.big_dyno_type).to eq("Standard-2X")
11
+ end
12
+ end
13
+
14
+ describe "#big_dyno_count" do
15
+ it "has a default" do
16
+ expect(config.big_dyno_count).to eq(3)
17
+ end
18
+ end
19
+
20
+ describe "#small_dyno_type" do
21
+ it "has a default" do
22
+ expect(config.small_dyno_type).to eq("Standard-1X")
23
+ end
24
+ end
25
+
26
+ describe "#small_dyno_count" do
27
+ it "has a default" do
28
+ expect(config.small_dyno_count).to eq(1)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+ require 'heroku-scaler/web_scale'
3
+
4
+ module HerokuScaler
5
+ class TestConfig
6
+ def app_name
7
+ "bonanza"
8
+ end
9
+
10
+ def big_dyno_type
11
+ "big-boy"
12
+ end
13
+
14
+ def big_dyno_count
15
+ 99
16
+ end
17
+
18
+ def small_dyno_type
19
+ "small-boy"
20
+ end
21
+
22
+ def small_dyno_count
23
+ 9
24
+ end
25
+
26
+ def auth_token
27
+ "some-token"
28
+ end
29
+ end
30
+
31
+ class TestPlatformAPI
32
+ def self.connect_oauth(token)
33
+ TestHeroku.new
34
+ end
35
+ end
36
+
37
+ class TestHeroku
38
+ def formation
39
+ TestFormation.new
40
+ end
41
+ end
42
+
43
+ class TestFormation
44
+ def update(app, type, hash)
45
+ end
46
+ end
47
+
48
+ describe WebScale do
49
+ let(:platform_api) { TestPlatformAPI }
50
+ let(:scaler) { HerokuScaler::WebScale.new(TestConfig.new, platform_api) }
51
+
52
+ describe "#up!" do
53
+ it "calls update" do
54
+ expect_any_instance_of(TestFormation).to receive(:update).with(
55
+ "bonanza",
56
+ "web",
57
+ {
58
+ size: "big-boy",
59
+ quantity: 99
60
+ }
61
+ )
62
+ scaler.up!
63
+ end
64
+ end
65
+
66
+ describe "#down!" do
67
+ it "calls update" do
68
+ expect_any_instance_of(TestFormation).to receive(:update).with(
69
+ "bonanza",
70
+ "web",
71
+ {
72
+ size: "small-boy",
73
+ quantity: 9
74
+ }
75
+ )
76
+ scaler.down!
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'heroku-scaler'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-scaler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - stirlingolson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-12 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: platform-api
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
27
41
  description: A simple script to allow cron-based scaling of a Heroku app
28
42
  email: seo@foraker.com
29
43
  executables: []
@@ -31,13 +45,19 @@ extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
33
47
  - ".gitignore"
48
+ - Gemfile
34
49
  - LICENSE
35
50
  - README.md
36
51
  - heroku-scaler.gemspec
37
52
  - lib/heroku-scaler.rb
53
+ - lib/heroku-scaler/config.rb
38
54
  - lib/heroku-scaler/railtie.rb
39
55
  - lib/heroku-scaler/version.rb
56
+ - lib/heroku-scaler/web_scale.rb
40
57
  - lib/tasks/heroku_scale.rake
58
+ - spec/lib/heroku-scaler/config_spec.rb
59
+ - spec/lib/heroku-scaler/web_scale_spec.rb
60
+ - spec/spec_helper.rb
41
61
  homepage: https://github.com/foraker/heroku-scaler
42
62
  licenses:
43
63
  - MIT
@@ -58,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
78
  version: '0'
59
79
  requirements: []
60
80
  rubyforge_project:
61
- rubygems_version: 2.2.2
81
+ rubygems_version: 2.4.5.1
62
82
  signing_key:
63
83
  specification_version: 4
64
84
  summary: Heroku Scaler