Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
4 bin/worker
@@ -29,8 +29,8 @@ def load_rails_and_run
begin
puts "#!load-rails!begin!#{Time.now.utc.xmlschema(6)}"
require File.expand_path(File.dirname(__FILE__) + '/../../../../config/boot')
- puts "RAILS_ROOT=#{RAILS_ROOT.inspect}"
- require RAILS_ROOT + '/config/environment'
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../config/environment')
+ puts "RAILS_ROOT=#{Rails.root}"
ensure
puts "#!load-rails!end!#{Time.now.utc.xmlschema(6)}"
end
View
2  lib/async_observer/queue.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
View
4 lib/async_observer/util.rb
@@ -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
View
36 lib/async_observer/worker.rb
@@ -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

No commit comments for this range

Something went wrong with that request. Please try again.