Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents adc9d1c + ba4f487 commit b80b286158e0e36a628e5e32f3aab11a0c252f66 Michael van Rooijen committed Jun 28, 2011
View
@@ -0,0 +1,29 @@
+0.1.3 / 2011-05-01
+
+[full changelog](https://github.com/meskyanichi/hirefire/compare/0.1.2...0.1.3)
+
+* Enhancements
+ * Bumps Heroku gem requirement to ~> 2.0
+
+0.1.2 / 2011-05-01
+
+[full changelog](https://github.com/meskyanichi/hirefire/compare/0.1.1...0.1.2)
+
+* Enhancements
+ * Add min_workers option (Sam Oliver)
+ * Gracefully handle RestClient exceptions (Nathaniel Bibler)
+ * Add Rails 2 compatibility (Estanislau Trepat)
+ * Performance improvements
+
+0.1.1 / 2011-04-15
+
+[full changelog](https://github.com/meskyanichi/hirefire/compare/0.1.0...0.1.1)
+
+* Enhancements
+ * Add support for Resque workers
+ * Add functional job/worker ratio definition option (Dirk Gadsden)
+ * Improve overall performance
+
+0.1.0 / 2011-04-10
+
+* Initial release.
View
@@ -17,6 +17,18 @@ Author
Drop me a message for any questions, suggestions, requests, bugs or submit them to the [issue log](https://github.com/meskyanichi/hirefire/issues).
+HireFireApp.com - The Heroku Worker Manager - BETA
+--------------------------------------------------
+
+*This is not part of the "HireFire open source" project, but it could potentially help support my open source projects!*
+
+I would like to announce the release of a **new service** I've been working on, called **HireFireApp**. The goal is essentially the same as the open source HireFire project, except that it's considered more **stable/reliable** and **a lot more performant**.
+
+The service is currently in beta, so feel free to create a free account and try it out!
+
+Check out the [official website](http://hirefireapp.com) for more information: [http://hirefireapp.com](http://hirefireapp.com)
+
+
Setting it up
-------------
View
@@ -0,0 +1,12 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rake'
+require 'rspec/core/rake_task'
+
+task :default => :spec
+
+desc "Run all examples"
+RSpec::Core::RakeTask.new('spec') do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+end
View
@@ -1,6 +1,7 @@
# encoding: utf-8
-require File.expand_path(File.dirname(__FILE__) + '/lib/hirefire')
+$:.push File.expand_path('../lib', __FILE__)
+require 'hirefire/version'
Gem::Specification.new do |gem|
@@ -23,7 +24,7 @@ Gem::Specification.new do |gem|
##
# Production gem dependencies
- gem.add_dependency 'heroku', ['~> 2.0.0']
+ gem.add_dependency 'heroku', ['>= 1.4']
gem.add_dependency 'rush', ['~> 0.6.7']
end
View
@@ -1,98 +1,56 @@
# encoding: utf-8
module HireFire
+ autoload :Configuration, 'hirefire/configuration'
+ autoload :Environment, 'hirefire/environment'
+ autoload :Initializer, 'hirefire/initializer'
+ autoload :Backend, 'hirefire/backend'
+ autoload :Logger, 'hirefire/logger'
+ autoload :Version, 'hirefire/version'
- ##
- # HireFire constants
- LIB_PATH = File.dirname(__FILE__)
- HIREFIRE_PATH = File.join(LIB_PATH, 'hirefire')
- ENVIRONMENT_PATH = File.join(HIREFIRE_PATH, 'environment')
- BACKEND_PATH = File.join(HIREFIRE_PATH, 'backend')
- WORKERS_PATH = File.join(HIREFIRE_PATH, 'workers')
+ class << self
- ##
- # HireFire namespace
- autoload :Configuration, File.join(HIREFIRE_PATH, 'configuration')
- autoload :Environment, File.join(HIREFIRE_PATH, 'environment')
- autoload :Initializer, File.join(HIREFIRE_PATH, 'initializer')
- autoload :Backend, File.join(HIREFIRE_PATH, 'backend')
- autoload :Logger, File.join(HIREFIRE_PATH, 'logger')
- autoload :Version, File.join(HIREFIRE_PATH, 'version')
-
- ##
- # HireFire::Environment namespace
- module Environment
- autoload :Base, File.join(ENVIRONMENT_PATH, 'base')
- autoload :Heroku, File.join(ENVIRONMENT_PATH, 'heroku')
- autoload :Local, File.join(ENVIRONMENT_PATH, 'local')
- autoload :Noop, File.join(ENVIRONMENT_PATH, 'noop')
- end
-
- ##
- # HireFire::Workers namespace
- module Workers
- autoload :DelayedJob, File.join(WORKERS_PATH, 'delayed_job')
- autoload :Resque, File.join(WORKERS_PATH, 'resque')
- end
-
- ##
- # HireFire::Backend namespace
- module Backend
- DELAYED_JOB_PATH = File.join(BACKEND_PATH, 'delayed_job')
- RESQUE_PATH = File.join(BACKEND_PATH, 'resque')
+ attr_writer :configuration
##
- # HireFire::Backend::DelayedJob namespace
- module DelayedJob
- autoload :ActiveRecord, File.join(DELAYED_JOB_PATH, 'active_record')
- autoload :ActiveRecord2, File.join(DELAYED_JOB_PATH, 'active_record_2')
- autoload :Mongoid, File.join(DELAYED_JOB_PATH, 'mongoid')
+ # This method is used to configure HireFire
+ #
+ # @yield [config] the instance of HireFire::Configuration class
+ # @yieldparam [Fixnum] max_workers default: 1 (set at least 1)
+ # @yieldparam [Array] job_worker_ratio default: see example
+ # @yieldparam [Symbol, nil] environment (:heroku, :local, :noop or nil) - default: nil
+ #
+ # @note Every param has it's own defaults. It's best to leave the environment param at "nil".
+ # When environment is set to "nil", it'll default to the :noop environment. This basically means
+ # that you have to run "rake jobs:work" yourself from the console to get the jobs running in development mode.
+ # In production, it'll automatically use :heroku if deployed to the Heroku platform.
+ #
+ # @example
+ # HireFire.configure do |config|
+ # config.environment = nil
+ # config.max_workers = 5
+ # config.min_workers = 0
+ # config.job_worker_ratio = [
+ # { :jobs => 1, :workers => 1 },
+ # { :jobs => 15, :workers => 2 },
+ # { :jobs => 35, :workers => 3 },
+ # { :jobs => 60, :workers => 4 },
+ # { :jobs => 80, :workers => 5 }
+ # ]
+ # end
+ #
+ # @return [nil]
+ def configure
+ yield(configuration); nil
end
##
- # HireFire::Backend::Resque namespace
- module Resque
- autoload :Redis, File.join(RESQUE_PATH, 'redis')
+ # Instantiates a new HireFire::Configuration
+ # instance and instance variable caches it
+ def configuration
+ @configuration ||= HireFire::Configuration.new
end
- end
-
- ##
- # This method is used to configure HireFire
- #
- # @yield [config] the instance of HireFire::Configuration class
- # @yieldparam [Fixnum] max_workers default: 1 (set at least 1)
- # @yieldparam [Array] job_worker_ratio default: see example
- # @yieldparam [Symbol, nil] environment (:heroku, :local, :noop or nil) - default: nil
- #
- # @note Every param has it's own defaults. It's best to leave the environment param at "nil".
- # When environment is set to "nil", it'll default to the :noop environment. This basically means
- # that you have to run "rake jobs:work" yourself from the console to get the jobs running in development mode.
- # In production, it'll automatically use :heroku if deployed to the Heroku platform.
- #
- # @example
- # HireFire.configure do |config|
- # config.environment = nil
- # config.max_workers = 5
- # config.min_workers = 0
- # config.job_worker_ratio = [
- # { :jobs => 1, :workers => 1 },
- # { :jobs => 15, :workers => 2 },
- # { :jobs => 35, :workers => 3 },
- # { :jobs => 60, :workers => 4 },
- # { :jobs => 80, :workers => 5 }
- # ]
- # end
- #
- # @return [nil]
- def self.configure
- yield(configuration); nil
- end
- ##
- # Instantiates a new HireFire::Configuration
- # instance and instance variable caches it
- def self.configuration
- @configuration ||= HireFire::Configuration.new
end
end
@@ -106,7 +64,7 @@ def self.configuration
# and the desired mapper (ActiveRecord, Mongoid or Redis)
if defined?(Rails)
if defined?(Rails::Railtie)
- require File.join(HireFire::HIREFIRE_PATH, 'railtie')
+ require 'hirefire/railtie'
else
HireFire::Initializer.initialize!
end
View
@@ -2,6 +2,8 @@
module HireFire
module Backend
+ autoload :DelayedJob, 'hirefire/backend/delayed_job'
+ autoload :Resque, 'hirefire/backend/resque'
##
# Load the correct module (ActiveRecord, Mongoid or Redis)
@@ -0,0 +1,11 @@
+# encoding: utf-8
+
+module HireFire
+ module Backend
+ module DelayedJob
+ autoload :ActiveRecord, 'hirefire/backend/delayed_job/active_record'
+ autoload :ActiveRecord2, 'hirefire/backend/delayed_job/active_record_2'
+ autoload :Mongoid, 'hirefire/backend/delayed_job/mongoid'
+ end
+ end
+end
@@ -0,0 +1,9 @@
+# encoding: utf-8
+
+module HireFire
+ module Backend
+ module Resque
+ autoload :Redis, 'hirefire/backend/resque/redis'
+ end
+ end
+end
@@ -2,6 +2,10 @@
module HireFire
module Environment
+ autoload :Base, 'hirefire/environment/base'
+ autoload :Heroku, 'hirefire/environment/heroku'
+ autoload :Local, 'hirefire/environment/local'
+ autoload :Noop, 'hirefire/environment/noop'
##
# This module gets included in either:
@@ -163,12 +163,16 @@ def hire
# If there are workers active, but there are no more pending jobs,
# then fire all the workers or set to the minimum_workers
#
- # @return [nil]
+ # @return [Boolean] if the workers have been fired
def fire
if jobs == 0 and workers > min_workers
Logger.message("All queued jobs have been processed. " + (min_workers > 0 ? "Setting workers to #{min_workers}." : "Firing all workers."))
workers(min_workers)
+
+ return true
end
+
+ return false
end
private
@@ -46,7 +46,7 @@ def self.initialize!
##
# Load Delayed Job extensions, this will patch Delayed::Worker
# to implement the necessary hooks to invoke HireFire from
- require File.join(HireFire::WORKERS_PATH, 'delayed_job')
+ require 'hirefire/workers/delayed_job'
end
##
@@ -65,7 +65,7 @@ def self.initialize!
##
# Load Resque extensions, this will patch Resque, Resque::Job and Resque::Worker
# to implement the necessary hooks to invoke HireFire from
- require File.join(HireFire::WORKERS_PATH, 'resque')
+ require 'hirefire/workers/resque'
end
end
View
@@ -32,7 +32,7 @@ class Railtie < Rails::Railtie
# If Resque is loaded, then we load the Resque rake task
# that'll allow Heroku to start up Resque as a worker
if defined?(::Resque)
- require File.join(WORKERS_PATH, 'resque', 'tasks.rb')
+ require 'hirefire/workers/resque/tasks'
end
end
View
@@ -6,7 +6,7 @@ module Version
##
# @return [String] the current version of the HireFire gem
def self.current
- '0.1.3'
+ '0.1.4'
end
end
View
@@ -0,0 +1,8 @@
+# encoding: utf-8
+
+module HireFire
+ module Workers
+ autoload :DelayedJob, 'hirefire/workers/delayed_job'
+ autoload :Resque, 'hirefire/workers/resque'
+ end
+end
@@ -59,8 +59,7 @@ def start
# If this is the case it'll command the current environment to fire all the hired workers
# and then immediately break out of this infinite loop.
if queued.jobs == 0
- Delayed::Job.environment.fire
- break
+ break if Delayed::Job.environment.fire
end
break if $exit
@@ -41,12 +41,11 @@ def work(interval = 5.0, &block)
# If this is the case it'll command the current environment to fire all the hired workers
# and then immediately break out of this infinite loop.
if (::Resque::Job.jobs + ::Resque::Job.working) == 0
- ::Resque::Job.environment.fire
- break
- else
- sleep(interval)
+ break if ::Resque::Job.environment.fire
end
+ sleep(interval)
+
end
end
Oops, something went wrong.

0 comments on commit b80b286

Please sign in to comment.