Skip to content

Commit

Permalink
Version bump to 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lostboy committed Sep 30, 2010
1 parent 739125e commit 986162c
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use 1.9.2@workless
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source :gemcutter

gem "heroku"
gem "rush"
28 changes: 28 additions & 0 deletions Gemfile.lock
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
7 changes: 5 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
require 'rubygems'
require 'rake'
require 'bundler'

begin
require 'jeweler'

Jeweler::Tasks.new do |gem|
gem.name = "workless"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.summary = %Q{Use delayed job workers only when theyre needed}
gem.description = %Q{Extension to Delayed Job to enable workers to scale up when needed}
gem.email = "paul.crabtree@gmail.com"
gem.homepage = "http://github.com/lostboy/workless"
gem.authors = ["lostboy"]
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
gem.add_bundler_dependencies
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
4 changes: 4 additions & 0 deletions lib/workless.rb
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)
9 changes: 9 additions & 0 deletions lib/workless/railtie.rb
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
35 changes: 35 additions & 0 deletions lib/workless/scaler.rb
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
15 changes: 15 additions & 0 deletions lib/workless/scalers/base.rb
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
33 changes: 33 additions & 0 deletions lib/workless/scalers/heroku.rb
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
27 changes: 27 additions & 0 deletions lib/workless/scalers/local.rb
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
59 changes: 59 additions & 0 deletions workless.gemspec
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

0 comments on commit 986162c

Please sign in to comment.