Skip to content

Commit b2e3dab

Browse files
committed
Added ability set the size of dynos when scaling
1 parent c1cf786 commit b2e3dab

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ heroku config:add WORKLESS_WORKERS_RATIO=50
106106

107107
In this example, it will scale up to a maximum of 10 workers, firing up 1 worker for every 50 jobs on the queue. The minimum will be 0 workers, but you could set it to a higher value if you want.
108108

109+
## Worker size
110+
111+
By default heroku will scale using standard-1x dynos, if you wish to use a different pro dyno size use the following config variable:
112+
113+
<pre>
114+
heroku config:add WORKLESS_WORKER_SIZE=performance-m
115+
</pre>
116+
117+
Possible values for [dyno size](https://devcenter.heroku.com/articles/dyno-types)
118+
119+
Note: This will not work for Hobby dynos, switch to Professional to support configuring dyno size
120+
109121
## How does Workless work?
110122

111123
- `Delayed::Workless::Scaler` is mixed into the `Delayed::Job` class, which adds a bunch of callbacks to it.

lib/workless/scalers/heroku.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Heroku < Base
1111
def self.up
1212
return unless workers_needed > min_workers && workers < workers_needed
1313
updates = { "quantity": workers_needed }
14+
updates[:size] = worker_size if worker_size
1415
client.formation.update(ENV['APP_NAME'], 'worker', updates)
1516
end
1617

@@ -29,6 +30,7 @@ def self.workers
2930
# ENV['WORKLESS_WORKERS_RATIO']
3031
# ENV['WORKLESS_MAX_WORKERS']
3132
# ENV['WORKLESS_MIN_WORKERS']
33+
# ENV['WORKLESS_WORKER_SIZE']
3234
#
3335
def self.workers_needed
3436
[[(jobs.count.to_f / workers_ratio).ceil, max_workers].min, min_workers].max
@@ -49,6 +51,10 @@ def self.max_workers
4951
def self.min_workers
5052
ENV['WORKLESS_MIN_WORKERS'].present? ? ENV['WORKLESS_MIN_WORKERS'].to_i : 0
5153
end
54+
55+
def self.worker_size
56+
ENV['WORKLESS_WORKER_SIZE'].present? ? ENV['WORKLESS_WORKER_SIZE'] : nil
57+
end
5258
end
5359
end
5460
end

spec/workless/scalers/heroku_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
Delayed::Workless::Scaler::Heroku.client.formation.should_receive(:update).once.with(ENV['APP_NAME'], 'worker', updates)
2323
Delayed::Workless::Scaler::Heroku.up
2424
end
25+
26+
context 'with WORKLESS_WORKER_SIZE' do
27+
before do
28+
ENV['WORKLESS_WORKER_SIZE'] = 'performance-l'
29+
end
30+
31+
it 'should set the workers size to WORKLESS_WORKER_SIZE' do
32+
updates = { "quantity": 1, "size": "performance-l" }
33+
Delayed::Workless::Scaler::Heroku.client.formation.should_receive(:update).once.with(ENV['APP_NAME'], 'worker', updates)
34+
Delayed::Workless::Scaler::Heroku.up
35+
end
36+
end
2537
end
2638

2739
context 'with workers' do

0 commit comments

Comments
 (0)