Permalink
Browse files

More Rails 3 fixes. Use Rails.logger

  • Loading branch information...
topfunky committed Jan 31, 2010
1 parent 3c4e823 commit b29419789fe7ec20db0fd8073069f6e2e555a839
Showing with 21 additions and 21 deletions.
  1. +1 −1 lib/async_observer/queue.rb
  2. +2 −2 lib/async_observer/util.rb
  3. +18 −18 lib/async_observer/worker.rb
@@ -70,7 +70,7 @@ def put_call!(obj, sel, opts, args=[])
pri = pri + rand(fuzz + 1) if !:direct.equal?(pri)
code = gen(obj, sel, args)
- RAILS_DEFAULT_LOGGER.info("put #{pri} #{code}")
+ Rails.logger.info("put #{pri} #{code}")
put!(pkg(code, worker_opts), pri, delay, ttr, tube)
end
@@ -22,10 +22,10 @@ module AsyncObserver; end
module AsyncObserver::Util
def log_bracketed(name)
begin
- RAILS_DEFAULT_LOGGER.info "#!#{name}!begin!#{Time.now.utc.xmlschema(6)}"
+ Rails.logger.info "#!#{name}!begin!#{Time.now.utc.xmlschema(6)}"
yield()
ensure
- RAILS_DEFAULT_LOGGER.info "#!#{name}!end!#{Time.now.utc.xmlschema(6)}"
+ Rails.logger.info "#!#{name}!end!#{Time.now.utc.xmlschema(6)}"
end
end
end
@@ -75,11 +75,11 @@ def main_loop()
def startup()
log_bracketed('worker-startup') do
appver = AsyncObserver::Queue.app_version
- RAILS_DEFAULT_LOGGER.info "pid is #{$$}"
- RAILS_DEFAULT_LOGGER.info "app version is #{appver}"
+ Rails.logger.info "pid is #{$$}"
+ Rails.logger.info "app version is #{appver}"
mark_db_socket_close_on_exec()
if AsyncObserver::Queue.queue.nil?
- RAILS_DEFAULT_LOGGER.info 'no queue has been configured'
+ Rails.logger.info 'no queue has been configured'
exit(1)
end
AsyncObserver::Queue.queue.watch(appver) if appver
@@ -140,13 +140,13 @@ def get_job()
rescue Beanstalk::DeadlineSoonError
# Do nothing; immediately try again, giving the user a chance to
# clean up in the before_reserve hook.
- RAILS_DEFAULT_LOGGER.info 'Job deadline soon; you should clean up.'
+ Rails.logger.info 'Job deadline soon; you should clean up.'
rescue Exception => ex
@q_hint = nil # in case there's something wrong with this conn
- RAILS_DEFAULT_LOGGER.info(
+ Rails.logger.info(
"#{ex.class}: #{ex}\n" + ex.backtrace.join("\n"))
- RAILS_DEFAULT_LOGGER.info 'something is wrong. We failed to get a job.'
- RAILS_DEFAULT_LOGGER.info "sleeping for #{SLEEP_TIME}s..."
+ Rails.logger.info 'something is wrong. We failed to get a job.'
+ Rails.logger.info "sleeping for #{SLEEP_TIME}s..."
sleep(SLEEP_TIME)
end
end
@@ -161,10 +161,10 @@ def dispatch(job)
def safe_dispatch(job)
log_bracketed('worker-dispatch') do
- RAILS_DEFAULT_LOGGER.info "got #{job.inspect}:\n" + job.body
+ Rails.logger.info "got #{job.inspect}:\n" + job.body
log_bracketed('job-stats') do
job.stats.each do |k,v|
- RAILS_DEFAULT_LOGGER.info "#{k}=#{v}"
+ Rails.logger.info "#{k}=#{v}"
end
end
begin
@@ -181,9 +181,9 @@ def safe_dispatch(job)
end
def flush_logger
- if defined?(RAILS_DEFAULT_LOGGER) &&
- RAILS_DEFAULT_LOGGER.respond_to?(:flush)
- RAILS_DEFAULT_LOGGER.flush
+ if defined?(Rails.logger) &&
+ Rails.logger.respond_to?(:flush)
+ Rails.logger.flush
end
end
@@ -196,14 +196,14 @@ def handle_error(job, ex)
end
def self.default_handle_error(job, ex)
- RAILS_DEFAULT_LOGGER.info "Job failed: #{job.server}/#{job.id}"
- RAILS_DEFAULT_LOGGER.info("#{ex.class}: #{ex}\n" + ex.backtrace.join("\n"))
+ Rails.logger.info "Job failed: #{job.server}/#{job.id}"
+ Rails.logger.info("#{ex.class}: #{ex}\n" + ex.backtrace.join("\n"))
job.decay()
rescue Beanstalk::UnexpectedResponse
end
def run_ao_job(job)
- RAILS_DEFAULT_LOGGER.info 'running as async observer job'
+ Rails.logger.info 'running as async observer job'
f = self.class.before_filter
f.call(job) if f
job.delete if job.ybody[:delete_first]
@@ -226,12 +226,12 @@ def async_observer_job?(job)
end
def run_other(job)
- RAILS_DEFAULT_LOGGER.info 'trying custom handler'
+ Rails.logger.info 'trying custom handler'
self.class.handle.call(job)
end
def do_all_work()
- RAILS_DEFAULT_LOGGER.info 'finishing all running jobs. interrupt again to kill them.'
+ Rails.logger.info 'finishing all running jobs. interrupt again to kill them.'
f = self.class.finish
f.call() if f
end
@@ -249,7 +249,7 @@ def set_close_on_exec()
@net.set_close_on_exec()
else
# we are in the c mysql binding
- RAILS_DEFAULT_LOGGER.info "Warning: we are using the C mysql binding, can't set close-on-exec"
+ Rails.logger.info "Warning: we are using the C mysql binding, can't set close-on-exec"
end
end
end

0 comments on commit b294197

Please sign in to comment.