workless 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@workless
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ gem "heroku"
4
+ gem "rush"
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ configuration (1.1.0)
5
+ fattr (2.1.0)
6
+ heroku (1.10.8)
7
+ json_pure (>= 1.2.0, < 1.5.0)
8
+ launchy (~> 0.3.2)
9
+ rest-client (>= 1.4.0, < 1.7.0)
10
+ json_pure (1.4.6)
11
+ launchy (0.3.7)
12
+ configuration (>= 0.0.5)
13
+ rake (>= 0.8.1)
14
+ mime-types (1.16)
15
+ rake (0.8.7)
16
+ rest-client (1.6.1)
17
+ mime-types (>= 1.16)
18
+ rush (0.6.7)
19
+ session
20
+ session (3.1.0)
21
+ fattr
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ heroku
28
+ rush
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 lostboy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = workless
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 lostboy. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+
5
+ begin
6
+ require 'jeweler'
7
+
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "workless"
10
+ gem.summary = %Q{Use delayed job workers only when theyre needed}
11
+ gem.description = %Q{Extension to Delayed Job to enable workers to scale up when needed}
12
+ gem.email = "paul.crabtree@gmail.com"
13
+ gem.homepage = "http://github.com/lostboy/workless"
14
+ gem.authors = ["lostboy"]
15
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
+ gem.add_bundler_dependencies
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "workless #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/workless.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ require File.dirname(__FILE__) + "/workless/scalers/base"
3
+ require File.dirname(__FILE__) + "/workless/scaler"
4
+ require File.dirname(__FILE__) + "/workless/railtie" if defined?(Rails::Railtie)
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+
3
+ module Delayed
4
+ class Railtie < Rails::Railtie
5
+ initializer :after_initialize do
6
+ Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::ActiveRecord::Job)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module Delayed
2
+ module Workless
3
+ module Scaler
4
+
5
+ def self.included(base)
6
+
7
+ base.send :extend, ClassMethods
8
+ base.class_eval do
9
+ after_destroy "self.class.scaler.down"
10
+ before_create "self.class.scaler.up"
11
+ after_update "self.class.scaler.down", :unless => Proc.new {|r| r.failed_at.nil? }
12
+ end
13
+
14
+ end
15
+
16
+ module ClassMethods
17
+ def scaler
18
+ @scaler ||= if ENV.include?("HEROKU_UPID")
19
+ require File.dirname(__FILE__) + "/scalers/heroku"
20
+ Scaler::Heroku.new
21
+ else
22
+ require File.dirname(__FILE__) + "/scalers/local"
23
+ Scaler::Local.new
24
+ end
25
+ end
26
+
27
+ def scaler=(scaler)
28
+ @scaler = scaler
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'delayed_job'
2
+
3
+ module Delayed
4
+ module Workless
5
+ module Scaler
6
+
7
+ class Base
8
+ def jobs
9
+ Delayed::Job.where(:failed_at => nil)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ require 'heroku'
2
+
3
+ module Delayed
4
+ module Workless
5
+ module Scaler
6
+
7
+ class Heroku < Base
8
+
9
+ require "heroku"
10
+
11
+ def up
12
+ client.set_workers(ENV['APP_NAME'], 1) if workers == 0
13
+ end
14
+
15
+ def down
16
+ client.set_workers(ENV['APP_NAME'], 0) unless workers == 0 or jobs.count > 0
17
+ end
18
+
19
+ def workers
20
+ client.info(ENV['APP_NAME'])[:workers].to_i
21
+ end
22
+
23
+ private
24
+
25
+ def client
26
+ @client ||= Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASSWORD'])
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ require 'rush'
2
+
3
+ module Delayed
4
+ module Workless
5
+ module Scaler
6
+
7
+ class Local < Base
8
+
9
+ def up
10
+ Rush::Box.new[Rails.root].bash("rake jobs:work", :background => true)
11
+ true
12
+ end
13
+
14
+ def down
15
+ Rush::Box.new.processes.filter(:cmdline => /rake jobs:work/).kill unless workers == 0 or jobs.count > 0
16
+ true
17
+ end
18
+
19
+ def workers
20
+ Rush::Box.new.processes.filter(:cmdline => /rake jobs:work/).size
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
27
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'workless'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWorkless < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
data/workless.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{workless}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["lostboy"]
12
+ s.date = %q{2010-09-30}
13
+ s.description = %q{Extension to Delayed Job to enable workers to scale up when needed}
14
+ s.email = %q{paul.crabtree@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".bundle/config",
21
+ ".document",
22
+ ".gitignore",
23
+ ".rvmrc",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "lib/workless.rb",
31
+ "lib/workless/railtie.rb",
32
+ "lib/workless/scaler.rb",
33
+ "lib/workless/scalers/base.rb",
34
+ "lib/workless/scalers/heroku.rb",
35
+ "lib/workless/scalers/local.rb",
36
+ "test/helper.rb",
37
+ "test/test_workless.rb",
38
+ "workless.gemspec"
39
+ ]
40
+ s.homepage = %q{http://github.com/lostboy/workless}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.7}
44
+ s.summary = %q{Use delayed job workers only when theyre needed}
45
+ s.test_files = [
46
+ "test/helper.rb",
47
+ "test/test_workless.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_runtime_dependency(%q<heroku>, [">= 0"])
57
+ s.add_runtime_dependency(%q<rush>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_dependency(%q<heroku>, [">= 0"])
61
+ s.add_dependency(%q<rush>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
65
+ s.add_dependency(%q<heroku>, [">= 0"])
66
+ s.add_dependency(%q<rush>, [">= 0"])
67
+ end
68
+ end
69
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workless
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - lostboy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: heroku
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rush
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *id003
59
+ description: Extension to Delayed Job to enable workers to scale up when needed
60
+ email: paul.crabtree@gmail.com
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files:
66
+ - LICENSE
67
+ - README.rdoc
68
+ files:
69
+ - .bundle/config
70
+ - .document
71
+ - .gitignore
72
+ - .rvmrc
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - LICENSE
76
+ - README.rdoc
77
+ - Rakefile
78
+ - VERSION
79
+ - lib/workless.rb
80
+ - lib/workless/railtie.rb
81
+ - lib/workless/scaler.rb
82
+ - lib/workless/scalers/base.rb
83
+ - lib/workless/scalers/heroku.rb
84
+ - lib/workless/scalers/local.rb
85
+ - test/helper.rb
86
+ - test/test_workless.rb
87
+ - workless.gemspec
88
+ has_rdoc: true
89
+ homepage: http://github.com/lostboy/workless
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options:
94
+ - --charset=UTF-8
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Use delayed job workers only when theyre needed
120
+ test_files:
121
+ - test/helper.rb
122
+ - test/test_workless.rb