Skip to content
Browse files

Rename logger proxies so they don't conflict with Celluloid

  • Loading branch information...
1 parent 3475c84 commit f68194a4170f930f0f7a406fba24208246e33946 @potatosalad committed May 29, 2012
View
37 lib/creeper.rb
@@ -27,8 +27,8 @@ class BadURL < RuntimeError; end
## default configuration ##
@beanstalk_url = ENV['BEANSTALK_URL'] || 'beanstalk://127.0.0.1/'
- @error_logger = ::Logger.new($stderr)
- @logger = ::Logger.new($stdout)
+ @err_logger = ::Logger.new($stderr)
+ @out_logger = ::Logger.new($stdout)
@patience_soft = 60
@patience_hard = 30
@pool_size = 2
@@ -101,7 +101,7 @@ def disconnect
def work(jobs = nil, size = nil)
require 'creeper/worker'
- Creeper.pool_size = size || Creeper.pool_size
+ Creeper.pool_size = size || Creeper.pool_
Creeper::Worker.work(jobs, Creeper.pool_size)
end
@@ -213,8 +213,8 @@ def finalizers
## queue ##
def enqueue(job, data = {}, options = {})
- # Logger.debug "#{Thread.current[:actor].inspect} Enqueueing #{job.inspect}, #{data.inspect}"#\n#{Celluloid::Actor.all.pretty_inspect}"
- Logger.debug "[#{Thread.current[:actor] ? Thread.current[:actor].subject.number : nil}] Enqueueing #{job.inspect}, #{data.inspect}" if $DEBUG
+ # OutLogger.debug "#{Thread.current[:actor].inspect} Enqueueing #{job.inspect}, #{data.inspect}"#\n#{Celluloid::Actor.all.pretty_inspect}"
+ OutLogger.debug "[#{Thread.current[:actor] ? Thread.current[:actor].subject.number : nil}] Enqueueing #{job.inspect}, #{data.inspect}" if $DEBUG
enqueue!(job, data, options)
rescue Beanstalk::NotConnected => e
disconnected(self, :enqueue, job, data, options)
@@ -236,8 +236,7 @@ def enqueue!(job, data = {}, options = {})
def error_work(worker, data, name, job)
(worker.stopped_at = Time.now).tap do |stopped_at|
error_message = "#{worker.prefix} Error after #{worker.time_in_milliseconds}ms #{worker.dump(job, name, data)}"
- ErrorLogger.error error_message
- Logger.error error_message
+ OutLogger.error error_message
end
end
@@ -264,19 +263,19 @@ def shutdown_workers
def start_work(worker, data, name, job)
(worker.started_at = Time.now).tap do |started_at|
- Logger.info "#{worker.prefix} Working #{worker.dump(job, name, data)}"
+ OutLogger.info "#{worker.prefix} Working #{worker.dump(job, name, data)}"
end
end
def stop_work(worker, data, name, job)
(worker.stopped_at = Time.now).tap do |stopped_at|
- Logger.info "#{worker.prefix} Finished in #{worker.time_in_milliseconds}ms #{worker.dump(job, name, data)}"
+ OutLogger.info "#{worker.prefix} Finished in #{worker.time_in_milliseconds}ms #{worker.dump(job, name, data)}"
end
end
def unregister_worker(worker, reason = nil)
reason ||= 'Stopping'
- Logger.info "#{worker.prefix} #{reason}"
+ OutLogger.info "#{worker.prefix} #{reason}"
lock.synchronize do
WORKERS.delete(worker.number)
end
@@ -296,7 +295,7 @@ def disconnected(target, method, *args, &block)
Thread.current[:beanstalk_connection_retries] ||= 0
if Thread.current[:beanstalk_connection_retries] >= retry_count
- Logger.error "Unable to connect to beanstalk after #{Thread.current[:beanstalk_connection_retries]} attempts"
+ OutLogger.error "Unable to connect to beanstalk after #{Thread.current[:beanstalk_connection_retries]} attempts"
Thread.current[:beanstalk_connection_retries] = 0
return false
end
@@ -313,7 +312,7 @@ def disconnected(target, method, *args, &block)
def soft_shutdown_workers(timeout)
Timeout.timeout(timeout) do
actors = Celluloid::Actor.all
- Logger.info "Gracefully stopping #{actors.size} actors..." if actors.size > 0
+ OutLogger.info "Gracefully stopping #{actors.size} actors..." if actors.size > 0
# Attempt to shut down the supervision tree, if available
Celluloid::Supervisor.root.terminate if Celluloid::Supervisor.root
@@ -336,14 +335,14 @@ def soft_shutdown_workers(timeout)
end
end
- Logger.info "Graceful stop completed cleanly"
+ OutLogger.info "Graceful stop completed cleanly"
end
end
def hard_shutdown_workers(timeout)
Timeout.timeout(timeout) do
actors = Celluloid::Actor.all
- Logger.info "Terminating #{actors.size} actors..." if actors.size > 0
+ OutLogger.info "Terminating #{actors.size} actors..." if actors.size > 0
# Attempt to shut down the supervision tree, if available
Celluloid::Supervisor.root.terminate if Celluloid::Supervisor.root
@@ -363,13 +362,13 @@ def hard_shutdown_workers(timeout)
end
end
- Logger.info "Termination completed cleanly"
+ OutLogger.info "Termination completed cleanly"
end
end
def kill_shutdown_workers
actors = Celluloid::Actor.all
- Logger.info "Killing #{actors.size} actors..." if actors.size > 0
+ OutLogger.info "Killing #{actors.size} actors..." if actors.size > 0
# Attempt to shut down the supervision tree, if available
Celluloid::Supervisor.root.kill if Celluloid::Supervisor.root
@@ -383,7 +382,7 @@ def kill_shutdown_workers
end
end
- Logger.info "Killing completed cleanly"
+ OutLogger.info "Killing completed cleanly"
end
def pool_managers
@@ -407,5 +406,5 @@ def working_actors
end
require 'creeper/creep'
-require 'creeper/error_logger'
-require 'creeper/logger'
+require 'creeper/err_logger'
+require 'creeper/out_logger'
View
10 lib/creeper/logger.rb → lib/creeper/err_logger.rb
@@ -1,25 +1,25 @@
module Creeper
- module Logger
+ module ErrLogger
module_function
# Send a debug message
def debug(string)
- Creeper.logger.debug(string) if Creeper.logger
+ Creeper.err_logger.debug(string) if Creeper.err_logger
end
# Send a info message
def info(string)
- Creeper.logger.info(string) if Creeper.logger
+ Creeper.err_logger.info(string) if Creeper.err_logger
end
# Send a warning message
def warn(string)
- Creeper.logger.warn(string) if Creeper.logger
+ Creeper.err_logger.warn(string) if Creeper.err_logger
end
# Send an error message
def error(string)
- Creeper.error_logger.error(string) if Creeper.error_logger
+ Creeper.err_logger.error(string) if Creeper.err_logger
end
# Handle a crash
View
14 lib/creeper/error_logger.rb → lib/creeper/out_logger.rb
@@ -1,25 +1,26 @@
module Creeper
- module ErrorLogger
- module_function
+ module OutLogger
+
+ extend self
# Send a debug message
def debug(string)
- Creeper.error_logger.debug(string) if Creeper.error_logger
+ Creeper.out_logger.debug(string) if Creeper.out_logger
end
# Send a info message
def info(string)
- Creeper.error_logger.info(string) if Creeper.error_logger
+ Creeper.out_logger.info(string) if Creeper.out_logger
end
# Send a warning message
def warn(string)
- Creeper.error_logger.warn(string) if Creeper.error_logger
+ Creeper.out_logger.warn(string) if Creeper.out_logger
end
# Send an error message
def error(string)
- Creeper.error_logger.error(string) if Creeper.error_logger
+ Creeper.out_logger.error(string) if Creeper.out_logger
end
# Handle a crash
@@ -33,5 +34,6 @@ def format_exception(exception)
str = "#{exception.class}: #{exception.to_s}\n"
str << exception.backtrace.join("\n")
end
+
end
end
View
8 lib/creeper/worker.rb
@@ -97,7 +97,7 @@ def initialize(jobs = nil)
@jobs = self.class.jobs_for(jobs)
Creeper.register_worker(self)
- Logger.info "#{prefix} Working #{self.jobs.size} jobs: [ #{self.jobs.join(' ')} ]"
+ OutLogger.info "#{prefix} Working #{self.jobs.size} jobs: [ #{self.jobs.join(' ')} ]"
end
def dump(job, name = nil, data = nil)
@@ -175,15 +175,15 @@ def start(short_circuit = false)
begin
job = reserve Creeper.reserve_timeout
rescue Beanstalk::TimedOut
- Logger.debug "#{prefix} Back to the unemployment line" if $DEBUG
+ OutLogger.debug "#{prefix} Back to the unemployment line" if $DEBUG
return false
end
exit if stopped?
Thread.current[:creeper_working] = true
- Logger.debug "#{prefix} Got #{job.inspect}" if $DEBUG
+ OutLogger.debug "#{prefix} Got #{job.inspect}" if $DEBUG
work! job # asynchronously go to work
rescue SystemExit => e
@@ -205,7 +205,7 @@ def finalize
finalizer.call
end
rescue => e
- Logger.crash "#{prefix} finalizer error", e
+ OutLogger.crash "#{prefix} finalizer error", e
end
end

0 comments on commit f68194a

Please sign in to comment.
Something went wrong with that request. Please try again.