Skip to content

Commit

Permalink
improve delayed jobs logging
Browse files Browse the repository at this point in the history
Enable auto_flush on the rails logging, so that the log is flushed to
disk after each log line, rather than each 1000 log lines.

Also redirect stdout and stderr if we've daemonized.

Change-Id: Iea89db81b4ac29a63614eff37da9216d6346a6f2
Reviewed-on: https://gerrit.instructure.com/2895
Tested-by: Hudson <[email protected]>
Reviewed-by: Bracken Mosbacker <[email protected]>
Reviewed-by: JT Olds <[email protected]>
  • Loading branch information
codekitchen committed Mar 30, 2011
1 parent e17e8fc commit 5892093
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions vendor/plugins/delayed_job/lib/delayed/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def initialize(config_filename)
raise ArgumentError,
"Invalid config file #{config_filename}"
end
logger.auto_flushing = true
end

def environment
Expand All @@ -57,18 +58,31 @@ def daemonize
@files_to_reopen << file unless file.closed?
end
Daemons.run_proc('delayed_jobs_pool',
:dir => "#{RAILS_ROOT}/tmp/pids",
:dir => "#{Rails.root}/tmp/pids",
:dir_mode => :normal) do
Dir.chdir(RAILS_ROOT)

Dir.chdir(Rails.root)
log_path = Rails.root+"log/delayed_job.log"

# Re-open file handles
@files_to_reopen.each do |file|
begin
file.reopen File.join(RAILS_ROOT, 'log', 'delayed_job.log'), 'a+'
file.reopen(log_path, 'a+')
file.sync = true
rescue ::Exception
end
end

if $0 == 'delayed_jobs_pool'
# TODO: Daemons library doesn't provide a great way to redirect
# stdout/stderr to an arbitrary log file, and it also doesn't provid
# a great way to detect if we actually daemonized (or if we're
# running in the FG).
STDOUT.reopen(log_path, 'a+')
STDERR.reopen(STDOUT)
STDOUT.sync = STDERR.sync = true
end

ActiveRecord::Base.connection_handler.clear_all_connections!

start
Expand Down

0 comments on commit 5892093

Please sign in to comment.