Skip to content

Commit

Permalink
Additional tweaks to documentation + deprecated Rails constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kdonovan committed May 15, 2011
1 parent 2650322 commit 219c69d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/apn/connection/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def socket

# Default to Rails or Merg logger, if available
def setup_logger
@logger = if defined?(Merb::Logger)
Merb.logger
@logger = if defined?(::Merb::Logger)
::Merb.logger
elsif defined?(::Rails.logger)
::Rails.logger
end
Expand All @@ -39,7 +39,7 @@ def setup_logger
# Log message to any logger provided by the user (e.g. the Rails logger).
# Accepts +log_level+, +message+, since that seems to make the most sense,
# and just +message+, to be compatible with Resque's log method and to enable
# sending verbose and very_verbose worker messages to e.g. the rails logger.#
# sending verbose and very_verbose worker messages to e.g. the rails logger.
#
# Perhaps a method definition of +message, +level+ would make more sense, but
# that's also the complete opposite of what anyone comming from rails would expect.
Expand All @@ -52,7 +52,8 @@ def log(level, message = nil)
self.logger.send(level, "#{Time.now}: #{message}")
end

# Log the message first, to ensure it reports what went wrong if in daemon mode. Then die, because something went horribly wrong.
# Log the message first, to ensure it reports what went wrong if in daemon mode.
# Then die, because something went horribly wrong.
def log_and_die(msg)
log(:fatal, msg)
raise msg
Expand All @@ -64,8 +65,9 @@ def apn_production?

# Get a fix on the .pem certificate we'll be using for SSL
def setup_paths
# Set option defaults
@opts[:cert_path] ||= File.join(File.expand_path(::Rails.root.to_s), "config", "certs") if defined?(::Rails.root.to_s)
# Set option defaults. RAILS_ROOT is still here not from Rails, but to handle passing in root from sender_daemon
@opts[:root_path] ||= defined?(::Rails.root) ? ::Rails.root.to_s : (defined?(RAILS_ROOT) ? RAILS_ROOT : '/')
@opts[:cert_path] ||= File.join(File.expand_path(@opts[:root_path]), "config", "certs")
@opts[:environment] ||= ::Rails.env if defined?(::Rails.env)

log_and_die("Missing certificate path. Please specify :cert_path when initializing class.") unless @opts[:cert_path]
Expand Down
6 changes: 4 additions & 2 deletions lib/apn/sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module APN
# which they apparently view as a DOS attack.
#
# Accepts <code>:environment</code> (production vs anything else) and <code>:cert_path</code> options on initialization. If called in a
# Rails context, will default to RAILS_ENV and RAILS_ROOT/config/certs. :environment will default to development.
# Rails context, <code>:cert_path</code> will default to "#{Rails.root}/config/certs" and <code>:environment</code>'s default will be set
# from Rails.env (production if Rails.env is production, development for any other Rails.env value).
#
# APN::Sender expects two files to exist in the specified <code>:cert_path</code> directory:
# <code>apn_production.pem</code> and <code>apn_development.pem</code>.
#
# If a socket error is encountered, will teardown the connection and retry again twice before admitting defeat.
# If a socket error is encountered, it will teardown the connection and retry again twice before admitting defeat.
class Sender < ::Resque::Worker
include APN::Connection::Base
TIMES_TO_RETRY_SOCKET_ERROR = 2
Expand Down

0 comments on commit 219c69d

Please sign in to comment.