Skip to content

Instantly share code, notes, and snippets.

@dbalatero
Created September 15, 2012 00:40
Show Gist options
  • Select an option

  • Save dbalatero/3725828 to your computer and use it in GitHub Desktop.

Select an option

Save dbalatero/3725828 to your computer and use it in GitHub Desktop.
module WarnMultipleBeforeForks
def self.extended(base)
base.class_eval do
alias_method_chain :before_fork, :multiple_warning
alias_method_chain :after_fork, :multiple_warning
end
end
def before_fork_with_multiple_warning(*args, &block)
if block_given?
@before_fork_with_multiple_warning_count ||= 0
@before_fork_with_multiple_warning_count += 1
count = @before_fork_with_multiple_warning_count
if count > 1
Rails.logger.warn "Warning: Resque#before_fork has had #{count} calls. This is bad!"
Rails.logger.warn caller.backtrace.to_s
end
end
before_fork_without_multiple_warning(*args, &block)
end
def after_fork_with_multiple_warning(*args, &block)
if block_given?
@after_fork_with_multiple_warning_count ||= 0
@after_fork_with_multiple_warning_count += 1
count = @after_fork_with_multiple_warning_count
if count > 1
Rails.logger.warn "Warning: Resque#after_fork has had #{count} calls. This is bad!"
Rails.logger.warn caller.backtrace.to_s
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment