Permalink
Browse files

Rework script/delayed_job so it can be used as a plugin or a gem. Clo…

…ses #2
  • Loading branch information...
1 parent d58a26d commit 4d76b8d4002751a0d7033c2f642f95676e73a474 @bkeepers bkeepers committed Sep 6, 2009
Showing with 9 additions and 12 deletions.
  1. +2 −4 generators/delayed_job/templates/script
  2. +7 −8 lib/delayed/command.rb
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby
-# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
-RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
-
-require File.join(File.dirname(__FILE__), *%w(.. vendor plugins delayed_job lib delayed command))
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
+require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
View
@@ -1,4 +1,3 @@
-require 'rubygems'
require 'daemons'
require 'optparse'
@@ -44,14 +43,14 @@ def daemonize
def run(worker_name = nil)
Dir.chdir(RAILS_ROOT)
- require File.join(RAILS_ROOT, 'config', 'environment')
- # Replace the default logger
- logger = Logger.new(File.join(RAILS_ROOT, 'log', 'delayed_job.log'))
- logger.level = ActiveRecord::Base.logger.level
- ActiveRecord::Base.logger = logger
- ActiveRecord::Base.clear_active_connections!
- Delayed::Worker.logger = logger
+ # Replace the default logger…too bad Rails doesn't make this easier
+ Rails.logger.instance_eval do
+ @log.reopen File.join(RAILS_ROOT, 'log', 'delayed_job.log')
+ end
+ Delayed::Worker.logger = Rails.logger
+ ActiveRecord::Base.connection.reconnect!
+
Delayed::Job.worker_name = "#{worker_name} #{Delayed::Job.worker_name}"
Delayed::Worker.new(@options).start

0 comments on commit 4d76b8d

Please sign in to comment.