heroku-resque-workers-scaler 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8dc50d2ecf4710e742e167c733230ed00e3bcae
4
- data.tar.gz: 7556b47f8cf4039e8a864b86397bd46e0690b20b
3
+ metadata.gz: 80444234023d5416075b0d6d274537223ec8b57b
4
+ data.tar.gz: f844a65e4d590cd1bdc7485981a97eb1f148b845
5
5
  SHA512:
6
- metadata.gz: c1e449b8d91ae50b69d2e839b84535fe4bdde196196277b873ffe409a6e3e7361e9cb343c947b7c6f9e486d180b97d4c85ea45201cec93eb733f0e51d2d922fd
7
- data.tar.gz: fca194c6dd9d4b8dc1e57c717602c06f4c7f179a73c1589dca8fd643c6a4e6916cab266e97696f54428a7608061d34c7829058fbf8f303dacdd68b0706a5503e
6
+ metadata.gz: 0278d725ae5a814419f546978d3633957c51bf8e2547c6e43141338225abaa518ff7933d465073cd71c779988c4c4ee3707041f1b39efd49fb90160be38d180c
7
+ data.tar.gz: d37a1fb67d184dcdc10c5c38b70163e830715bc73b08a66dd45fd69b0fb0f5677a555bfe22bdd8f5c92b0a1b9f12c9562b0f5d3ca038af2282fa08eea4c1916d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # Changelog VERSION = '0.3.0'
2
+ * feature
3
+ * Add another mode for thresholds
4
+
5
+ * bug fix
6
+ * fix size of working job count at ZERO instead of one
7
+
8
+ [Fullcahnges](https://github.com/joel/heroku-resque-workers-scaler/pull/8)
9
+
1
10
  # Changelog VERSION = '0.2.1'
2
11
 
3
12
  [Fullcahnges](https://github.com/joel/heroku-resque-workers-scaler/pull/7)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heroku-resque-workers-scaler (0.2.1)
4
+ heroku-resque-workers-scaler (0.3.0)
5
5
  platform-api (~> 0.2.0)
6
6
  resque (~> 1.25.2)
7
7
 
data/README.md CHANGED
@@ -26,7 +26,7 @@ You need to defined two vars for your heroku :
26
26
  ```
27
27
  heroku config:add HEROKU_API_KEY=your_api_key -a your_app_name
28
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
29
+ heroku config:add SAFE_MODE=true -a your_app_name
30
30
  ```
31
31
 
32
32
  ## Run localy
@@ -58,6 +58,7 @@ You can change the thresholds, environments of execution and the name of your wo
58
58
 
59
59
  Exmple YAML file contents:
60
60
 
61
+ mode: :thresholds # :fit, :half, :third
61
62
  thresholds:
62
63
  - :workers: 1
63
64
  :job_count: 1
@@ -67,6 +68,8 @@ Exmple YAML file contents:
67
68
  - production
68
69
  worker_name: resque
69
70
 
71
+ if you use `mode: :fit` the number of job is exactly the same of available worker, `:half` the number of worker is 1/2 of number of job in queue, and for `third` 1/3
72
+
70
73
  I just bundled it into a gem for easy inclusion into other projects.
71
74
 
72
75
  #### Usage
@@ -1,3 +1,4 @@
1
+ mode: :thresholds # :fit, :half, :third
1
2
  thresholds:
2
3
  - :workers: 1
3
4
  :job_count: 1
@@ -1,3 +1,8 @@
1
1
  require 'heroku-resque-workers-scaler/version'
2
2
  require 'heroku-resque-workers-scaler/scaler'
3
- require 'heroku-resque-workers-scaler/config'
3
+ require 'heroku-resque-workers-scaler/config'
4
+
5
+ begin
6
+ require 'pry'
7
+ rescue LoadError
8
+ end
@@ -5,6 +5,10 @@ module HerokuResqueAutoScale
5
5
  extend self
6
6
 
7
7
  CONFIG_FILE_NAME = 'scaler_config.yml'
8
+
9
+ def mode
10
+ @mode ||= config['mode']
11
+ end
8
12
 
9
13
  def thresholds
10
14
  @thresholds ||= config['thresholds']
@@ -54,7 +54,7 @@ module HerokuResqueAutoScale
54
54
  private
55
55
 
56
56
  def authorized?
57
- HerokuResqueAutoScale::Config.environments.include? _environment
57
+ Config.environments.include? _environment
58
58
  end
59
59
 
60
60
  def _environment
@@ -66,7 +66,7 @@ module HerokuResqueAutoScale
66
66
  end
67
67
 
68
68
  def worker_name
69
- HerokuResqueAutoScale::Config.worker_name
69
+ Config.worker_name
70
70
  end
71
71
 
72
72
  end
@@ -81,18 +81,27 @@ module HerokuResqueAutoScale
81
81
  end
82
82
 
83
83
  def after_enqueue_scale_up(*args)
84
- HerokuResqueAutoScale::Config.thresholds.reverse_each do |scale_info|
85
- # Run backwards so it gets set to the highest value first
86
- # Otherwise if there were 70 jobs, it would get set to 1, then 2, then 3, etc
87
-
88
- # If we have a job count greater than or equal to the job limit for this scale info
89
- if Scaler.job_count >= scale_info[:job_count]
90
- # Set the number of workers unless they are already set to a level we want. Don't scale down here!
91
- if Scaler.workers <= scale_info[:workers]
92
- Scaler.workers = scale_info[:workers]
84
+ case Config.mode
85
+ when :thresholds
86
+ Config.thresholds.reverse_each do |scale_info|
87
+ # Run backwards so it gets set to the highest value first
88
+ # Otherwise if there were 70 jobs, it would get set to 1, then 2, then 3, etc
89
+
90
+ # If we have a job count greater than or equal to the job limit for this scale info
91
+ if Scaler.job_count >= scale_info[:job_count]
92
+ # Set the number of workers unless they are already set to a level we want. Don't scale down here!
93
+ if Scaler.workers <= scale_info[:workers]
94
+ Scaler.workers = scale_info[:workers]
95
+ end
96
+ break # We've set or ensured that the worker count is high enough
93
97
  end
94
- break # We've set or ensured that the worker count is high enough
95
98
  end
99
+ when :fit
100
+ Scaler.workers = Scaler.job_count
101
+ when :half
102
+ Scaler.workers = (Scaler.job_count/2)
103
+ when :third
104
+ Scaler.workers = (Scaler.job_count/3)
96
105
  end
97
106
  end
98
107
 
@@ -101,6 +110,6 @@ module HerokuResqueAutoScale
101
110
  def scale_down
102
111
  # Nothing fancy, just shut everything down if we have no pending jobs
103
112
  # and one working job (which is this job)
104
- Scaler.workers = 0 if Scaler.job_count.zero? && Scaler.working_job_count == 1
113
+ Scaler.workers = 0 if Scaler.job_count.zero? && Scaler.working_job_count.zero?
105
114
  end
106
115
  end
@@ -1,3 +1,3 @@
1
1
  module HerokuResqueAutoScale
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  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.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Quezada