Class: Autoscale::Heroku
- Inherits:
-
Object
- Object
- Autoscale::Heroku
- Defined in:
- lib/autoscale/heroku.rb
Class Method Summary collapse
-
.app ⇒ Object
the app to scale.
- .calculate_required_workers ⇒ Object
-
.client ⇒ Object
heroku api client.
-
.down ⇒ Object
shutdown if no jobs exist.
- .job_count ⇒ Object
- .min_workers ⇒ Object
- .params ⇒ Object
-
.scale ⇒ Object
the scale.
-
.shutdown ⇒ Object
shutdown all workers.
-
.up ⇒ Object
scale workers based on scale.
- .workers ⇒ Object
- .workers=(qty) ⇒ Object
Class Method Details
.app ⇒ Object
the app to scale
54 55 56 |
# File 'lib/autoscale/heroku.rb', line 54 def app Autoscale.app end |
.calculate_required_workers ⇒ Object
39 40 41 |
# File 'lib/autoscale/heroku.rb', line 39 def calculate_required_workers (scale.rindex{|x| x <= job_count}.to_i + 1) end |
.client ⇒ Object
heroku api client
68 69 70 |
# File 'lib/autoscale/heroku.rb', line 68 def client @@client ||= ::Heroku::API.new( params ) end |
.down ⇒ Object
shutdown if no jobs exist
32 33 34 35 36 37 |
# File 'lib/autoscale/heroku.rb', line 32 def down if job_count < 1 QC.log(action: :scale, workers: min_workers) self.workers = min_workers end end |
.job_count ⇒ Object
19 20 21 |
# File 'lib/autoscale/heroku.rb', line 19 def job_count QC::Queries.count.to_i end |
.min_workers ⇒ Object
63 64 65 |
# File 'lib/autoscale/heroku.rb', line 63 def min_workers Autoscale.min || 0 end |
.params ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/autoscale/heroku.rb', line 43 def params { api_key: Autoscale.api_key || ENV['HEROKU_API_KEY'], connect_timeout: Autoscale.connect_timeout, read_timeout: Autoscale.read_timeout, write_timeout: Autoscale.write_timeout, mock: Autoscale.mock || false } end |
.scale ⇒ Object
the scale
59 60 61 |
# File 'lib/autoscale/heroku.rb', line 59 def scale Autoscale.scale || [1, 15, 30, 40, 50] end |
.shutdown ⇒ Object
shutdown all workers
15 16 17 |
# File 'lib/autoscale/heroku.rb', line 15 def shutdown self.workers = 0 end |
.up ⇒ Object
scale workers based on scale
24 25 26 27 28 29 |
# File 'lib/autoscale/heroku.rb', line 24 def up unless calculate_required_workers <= workers QC.log(action: :scale, workers: calculate_required_workers) self.workers = calculate_required_workers end end |
.workers ⇒ Object
6 7 8 |
# File 'lib/autoscale/heroku.rb', line 6 def workers client.get_app(app).body.fetch("workers", 0).to_i end |
.workers=(qty) ⇒ Object
10 11 12 |
# File 'lib/autoscale/heroku.rb', line 10 def workers=(qty) client.post_ps_scale(app, "worker", qty) end |