-
Notifications
You must be signed in to change notification settings - Fork 80
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
13 changed files
with
223 additions
and
3 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,2 @@ | ||
--- | ||
BUNDLE_DISABLE_SHARED_GEMS: "1" |
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 @@ | ||
rvm use 1.9.2@workless |
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,4 @@ | ||
source :gemcutter | ||
|
||
gem "heroku" | ||
gem "rush" |
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,28 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
configuration (1.1.0) | ||
fattr (2.1.0) | ||
heroku (1.10.8) | ||
json_pure (>= 1.2.0, < 1.5.0) | ||
launchy (~> 0.3.2) | ||
rest-client (>= 1.4.0, < 1.7.0) | ||
json_pure (1.4.6) | ||
launchy (0.3.7) | ||
configuration (>= 0.0.5) | ||
rake (>= 0.8.1) | ||
mime-types (1.16) | ||
rake (0.8.7) | ||
rest-client (1.6.1) | ||
mime-types (>= 1.16) | ||
rush (0.6.7) | ||
session | ||
session (3.1.0) | ||
fattr | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
heroku | ||
rush |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1 | ||
0.0.2 |
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,4 @@ | ||
|
||
require File.dirname(__FILE__) + "/workless/scalers/base" | ||
require File.dirname(__FILE__) + "/workless/scaler" | ||
require File.dirname(__FILE__) + "/workless/railtie" if defined?(Rails::Railtie) |
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,9 @@ | ||
require 'rails' | ||
|
||
module Delayed | ||
class Railtie < Rails::Railtie | ||
initializer :after_initialize do | ||
Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::ActiveRecord::Job) | ||
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,35 @@ | ||
module Delayed | ||
module Workless | ||
module Scaler | ||
|
||
def self.included(base) | ||
|
||
base.send :extend, ClassMethods | ||
base.class_eval do | ||
after_destroy "self.class.scaler.down" | ||
before_create "self.class.scaler.up" | ||
after_update "self.class.scaler.down", :unless => Proc.new {|r| r.failed_at.nil? } | ||
end | ||
|
||
end | ||
|
||
module ClassMethods | ||
def scaler | ||
@scaler ||= if ENV.include?("HEROKU_UPID") | ||
require File.dirname(__FILE__) + "/scalers/heroku" | ||
Scaler::Heroku.new | ||
else | ||
require File.dirname(__FILE__) + "/scalers/local" | ||
Scaler::Local.new | ||
end | ||
end | ||
|
||
def scaler=(scaler) | ||
@scaler = scaler | ||
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,15 @@ | ||
require 'delayed_job' | ||
|
||
module Delayed | ||
module Workless | ||
module Scaler | ||
|
||
class Base | ||
def jobs | ||
Delayed::Job.where(:failed_at => nil) | ||
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,33 @@ | ||
require 'heroku' | ||
|
||
module Delayed | ||
module Workless | ||
module Scaler | ||
|
||
class Heroku < Base | ||
|
||
require "heroku" | ||
|
||
def up | ||
client.set_workers(ENV['APP_NAME'], 1) if workers == 0 | ||
end | ||
|
||
def down | ||
client.set_workers(ENV['APP_NAME'], 0) unless workers == 0 or jobs.count > 0 | ||
end | ||
|
||
def workers | ||
client.info(ENV['APP_NAME'])[:workers].to_i | ||
end | ||
|
||
private | ||
|
||
def client | ||
@client ||= Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASSWORD']) | ||
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,27 @@ | ||
require 'rush' | ||
|
||
module Delayed | ||
module Workless | ||
module Scaler | ||
|
||
class Local < Base | ||
|
||
def up | ||
Rush::Box.new[Rails.root].bash("rake jobs:work", :background => true) | ||
true | ||
end | ||
|
||
def down | ||
Rush::Box.new.processes.filter(:cmdline => /rake jobs:work/).kill unless workers == 0 or jobs.count > 0 | ||
true | ||
end | ||
|
||
def workers | ||
Rush::Box.new.processes.filter(:cmdline => /rake jobs:work/).size | ||
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,59 @@ | ||
# Generated by jeweler | ||
# DO NOT EDIT THIS FILE DIRECTLY | ||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |s| | ||
s.name = %q{workless} | ||
s.version = "0.0.1" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["lostboy"] | ||
s.date = %q{2010-09-30} | ||
s.description = %q{Extension to Delayed Job to enable workers to scale up when needed} | ||
s.email = %q{paul.crabtree@gmail.com} | ||
s.extra_rdoc_files = [ | ||
"LICENSE", | ||
"README.rdoc" | ||
] | ||
s.files = [ | ||
".document", | ||
".gitignore", | ||
"LICENSE", | ||
"README.rdoc", | ||
"Rakefile", | ||
"VERSION", | ||
"lib/workless.rb", | ||
"test/helper.rb", | ||
"test/test_workless.rb" | ||
] | ||
s.homepage = %q{http://github.com/lostboy/workless} | ||
s.rdoc_options = ["--charset=UTF-8"] | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = %q{1.3.7} | ||
s.summary = %q{Use delayed job workers only when theyre needed} | ||
s.test_files = [ | ||
"test/helper.rb", | ||
"test/test_workless.rb" | ||
] | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | ||
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"]) | ||
s.add_runtime_dependency(%q<heroku>, [">= 0"]) | ||
s.add_runtime_dependency(%q<rush>, [">= 0"]) | ||
else | ||
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"]) | ||
s.add_dependency(%q<heroku>, [">= 0"]) | ||
s.add_dependency(%q<rush>, [">= 0"]) | ||
end | ||
else | ||
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"]) | ||
s.add_dependency(%q<heroku>, [">= 0"]) | ||
s.add_dependency(%q<rush>, [">= 0"]) | ||
end | ||
end | ||
|