Created
September 15, 2012 00:40
-
-
Save dbalatero/3725828 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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