Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ heroku config:add WORKLESS_WORKERS_RATIO=50

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.

## Worker size

By default heroku will scale using standard-1x dynos, if you wish to use a different pro dyno size use the following config variable:

<pre>
heroku config:add WORKLESS_WORKER_SIZE=performance-m
</pre>

Possible values for [dyno size](https://devcenter.heroku.com/articles/dyno-types)

Note: This will not work for Hobby dynos, switch to Professional to support configuring dyno size

## How does Workless work?

- `Delayed::Workless::Scaler` is mixed into the `Delayed::Job` class, which adds a bunch of callbacks to it.
Expand Down
6 changes: 6 additions & 0 deletions lib/workless/scalers/heroku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Heroku < Base
def self.up
return unless workers_needed > min_workers && workers < workers_needed
updates = { "quantity": workers_needed }
updates[:size] = worker_size if worker_size
client.formation.update(ENV['APP_NAME'], 'worker', updates)
end

Expand All @@ -29,6 +30,7 @@ def self.workers
# ENV['WORKLESS_WORKERS_RATIO']
# ENV['WORKLESS_MAX_WORKERS']
# ENV['WORKLESS_MIN_WORKERS']
# ENV['WORKLESS_WORKER_SIZE']
#
def self.workers_needed
[[(jobs.count.to_f / workers_ratio).ceil, max_workers].min, min_workers].max
Expand All @@ -49,6 +51,10 @@ def self.max_workers
def self.min_workers
ENV['WORKLESS_MIN_WORKERS'].present? ? ENV['WORKLESS_MIN_WORKERS'].to_i : 0
end

def self.worker_size
ENV['WORKLESS_WORKER_SIZE'].present? ? ENV['WORKLESS_WORKER_SIZE'] : nil
end
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/workless/scalers/heroku_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
Delayed::Workless::Scaler::Heroku.client.formation.should_receive(:update).once.with(ENV['APP_NAME'], 'worker', updates)
Delayed::Workless::Scaler::Heroku.up
end

context 'with WORKLESS_WORKER_SIZE' do
before do
ENV['WORKLESS_WORKER_SIZE'] = 'performance-l'
end

it 'should set the workers size to WORKLESS_WORKER_SIZE' do
updates = { "quantity": 1, "size": "performance-l" }
Delayed::Workless::Scaler::Heroku.client.formation.should_receive(:update).once.with(ENV['APP_NAME'], 'worker', updates)
Delayed::Workless::Scaler::Heroku.up
end
end
end

context 'with workers' do
Expand Down