forked from JustinLove/resque-heroku-autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Resque | ||
module Plugins | ||
module HerokuAutoscaler | ||
module Config | ||
extend self | ||
|
||
@new_worker_count = Proc.new {|pending| pending >0 ? 1 : 0} | ||
|
||
attr_writer :heroku_user | ||
def heroku_user | ||
@heroku_user || ENV['HEROKU_USER'] | ||
end | ||
|
||
attr_writer :heroku_pass | ||
def heroku_pass | ||
@heroku_pass || ENV['HEROKU_PASS'] | ||
end | ||
|
||
attr_writer :heroku_app | ||
def heroku_app | ||
@heroku_app || ENV['HEROKU_APP'] | ||
end | ||
|
||
def new_worker_count(pending=nil, *payload, &calculate_count) | ||
if calculate_count | ||
@new_worker_count = calculate_count | ||
else | ||
@new_worker_count.call(pending, *payload) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Resque::Plugins::HerokuAutoscaler | ||
VERSION = "0.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require 'rspec' | ||
require 'heroku' | ||
require 'resque' | ||
require 'resque/plugins/heroku_autoscaler/config' | ||
|
||
describe Resque::Plugins::HerokuAutoscaler::Config do | ||
describe ".heroku_user" do | ||
it "stores the given heroku user name" do | ||
subject.heroku_user = "my_user@example.com" | ||
subject.heroku_user.should == "my_user@example.com" | ||
end | ||
|
||
it "defaults to HEROKU_USER environment variable" do | ||
subject.heroku_user = nil | ||
ENV["HEROKU_USER"] = "user@example.com" | ||
subject.heroku_user.should == "user@example.com" | ||
end | ||
end | ||
|
||
describe ".heroku_pass" do | ||
it "stores the given heroku password" do | ||
subject.heroku_pass = "password" | ||
subject.heroku_pass.should == "password" | ||
end | ||
|
||
it "defaults to HEROKU_PASS environment variable" do | ||
subject.heroku_pass = nil | ||
ENV["HEROKU_PASS"] = "123" | ||
subject.heroku_pass.should == "123" | ||
end | ||
end | ||
|
||
describe ".heroku_app" do | ||
it "stores the given heroku application name" do | ||
subject.heroku_app = "my-grand-app" | ||
subject.heroku_app.should == "my-grand-app" | ||
end | ||
|
||
it "defaults to HEROKU_APP environment variable" do | ||
subject.heroku_app = nil | ||
ENV["HEROKU_APP"] = "yaa" | ||
subject.heroku_app.should == "yaa" | ||
end | ||
end | ||
|
||
describe ".new_worker_count" do | ||
before do | ||
@original_method = Resque::Plugins::HerokuAutoscaler::Config.instance_variable_get(:@new_worker_count) | ||
end | ||
|
||
after do | ||
Resque::Plugins::HerokuAutoscaler::Config.instance_variable_set(:@new_worker_count, @original_method) | ||
end | ||
|
||
it "should store a block as a Proc" do | ||
subject.new_worker_count do |pending| | ||
pending/5 | ||
end | ||
|
||
subject.new_worker_count(10).should == 2 | ||
end | ||
|
||
it "should be able to take the Resque job's payload as arguments" do | ||
subject.new_worker_count do |pending, queue| | ||
if queue == "test_queue" | ||
10 | ||
else | ||
pending/5 | ||
end | ||
end | ||
|
||
job_payload = ["test_queue", "more", "payload"] | ||
puts "job_payload: #{job_payload.inspect}" | ||
subject.new_worker_count(10, *job_payload).should == 10 | ||
end | ||
|
||
context "when the proc was not yet set" do | ||
before do | ||
subject.new_worker_count do |pending, queue| | ||
end | ||
it { subject.new_worker_count(0).should == 0 } | ||
it { subject.new_worker_count(1).should == 1 } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters