Browse files

no longer using daemons gem.

instead of using the old: 
  
    ./script/daemons start

use:

    ruby script/background

If you refer the ./script method just make script/background executable.

Currently, script/background is missing some of its original features. For examle it logs to the console when run as opposed to the Rails logs. The original functionality will be restored. The script now recognizes the file config/background.yml as its config file.
  • Loading branch information...
1 parent 825077b commit 24da4ca127ed0a12b73a931f432fb716897650cf jrwest committed Feb 26, 2010
View
1 Rakefile
@@ -7,7 +7,6 @@ begin
gem.homepage = "http://github.com/ncr/background-fu"
gem.authors = ["Jacek Becela"]
gem.files = Dir["*", "{lib}/**/*"]
- gem.add_dependency("daemons", ">= 1.0.10")
gem.has_rdoc = true
gem.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
end
View
5 lib/generators/background/background_generator.rb
@@ -22,10 +22,7 @@ def self.next_migration_number(dirname) #:nodoc:
end
def copy_daemons
- template 'background.rb', 'lib/daemons/background.rb'
- template 'background_ctl', 'lib/daemons/background_ctl'
- template 'daemons', 'script/daemons'
- template 'daemons.yml', 'config/daemons.yml'
+ template 'background.rb', 'script/background'
end
def copy_examples
View
23 lib/generators/background/templates/background.rb
@@ -1,22 +1,35 @@
#!/usr/bin/env ruby
+require "rubygems"
+require "rails"
+require "active_record"
+require "background_fu"
-require File.dirname(__FILE__) + "/../../config/environment"
+require File.dirname(__FILE__) + "/../config/boot"
+require File.dirname(__FILE__) + "/../config/environment"
Signal.trap("TERM") { exit }
-RAILS_DEFAULT_LOGGER.info("BackgroundFu: Starting daemon (bonus features #{Job.included_modules.include?(Job::BonusFeatures) ? "enabled" : "disabled"}).")
+puts "BackgroundFu: Starting up."
+#RAILS_DEFAULT_LOGGER.info("BackgroundFu: Starting daemon (bonus features #{Job.included_modules.include?(Job::BonusFeatures) ? "enabled" : "disabled"}).")
+puts "With Config:"
BackgroundFu::CONFIG.each do |k,v|
- RAILS_DEFAULT_LOGGER.info "BackgroundFu: #{k}: #{v.to_s}"
+ puts "\t#{k}: #{v.to_s}"
+# RAILS_DEFAULT_LOGGER.info "BackgroundFu: #{k}: #{v.to_s}"
end
-Job.cleanup_finished_jobs if BackgroundFu::CONFIG['cleanup_interval'] == :at_start
+if BackgroundFu::CONFIG['cleanup_interval'] == :on_startup
+ puts "Cleaning finished jobs...(on startup)"
+ Job.cleanup_finished_jobs
+end
loop do
if job = Job.find(:first, :conditions => ["state='pending' and start_at <= ?", Time.zone.now.to_s(:db)], :order => "priority desc, start_at asc")
+ puts "Found job: #{job.id}. Going to do what you asked with it now."
job.get_done!
else
- RAILS_DEFAULT_LOGGER.info("BackgroundFu: Waiting for jobs...")
+ puts "Waiting for jobs..."
+ #RAILS_DEFAULT_LOGGER.info("BackgroundFu: Waiting for jobs...")
sleep BackgroundFu::CONFIG['monitor_interval']
end
Job.cleanup_finished_jobs if BackgroundFu::CONFIG['cleanup_interval'] == :continuous
View
20 lib/generators/background/templates/background_ctl
@@ -1,20 +0,0 @@
-#!/usr/bin/env ruby
-require 'rubygems'
-require 'daemons'
-require 'yaml'
-require 'erb'
-
-class Hash
- def with_symbols!
- self.keys.each{|key| self[key.to_s.to_sym] = self[key] }; self
- end
-end
-
-options = YAML.load(
- ERB.new(
- IO.read(
- File.dirname(__FILE__) + "/../../config/daemons.yml"
- )).result).with_symbols!
-options[:dir_mode] = options[:dir_mode].to_sym
-
-Daemons.run File.dirname(__FILE__) + '/background.rb', options
View
2 lib/generators/background/templates/daemons
@@ -1,2 +0,0 @@
-#!/usr/bin/env ruby
-Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `nice ruby #{f} #{ARGV.first}`}
View
8 lib/generators/background/templates/daemons.yml
@@ -1,8 +0,0 @@
-dir_mode: script
-dir: ../../log
-multiple: false
-backtrace: true
-monitor: true
-background_fu:
- cleanup_interval: :on_startup # :on_startup or :continuous
- monitor_interval: 5 # seconds between checks for queued jobs

0 comments on commit 24da4ca

Please sign in to comment.