Skip to content
This repository has been archived by the owner on Jul 22, 2018. It is now read-only.

Commit

Permalink
Namespace ohai
Browse files Browse the repository at this point in the history
  • Loading branch information
itspriddle committed Jan 15, 2011
1 parent a9582a1 commit 01973be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
10 changes: 6 additions & 4 deletions lib/apnd.rb
Expand Up @@ -21,9 +21,11 @@ def self.configure
yield settings
end

end

#
# Write message to stdout with date
#
def self.ohai(message) #:nodoc:
puts "[%s] %s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"), message]
end

def ohai(message) #:nodoc:
puts "[%s] %s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"), message]
end
10 changes: 5 additions & 5 deletions lib/apnd/daemon.rb
Expand Up @@ -35,7 +35,7 @@ def initialize
#
def run!
EventMachine::run do
ohai "Starting APND Daemon v#{APND::Version} on #{@bind}:#{@port}"
APND.ohai "Starting APND Daemon v#{APND::Version} on #{@bind}:#{@port}"
EventMachine::start_server(@bind, @port, APND::Daemon::ServerConnection) do |server|
server.queue = @queue
end
Expand All @@ -54,19 +54,19 @@ def run!
def process_notifications!
count = @queue.size
if count > 0
ohai "Queue has #{count} item#{count == 1 ? '' : 's'}"
APND.ohai "Queue has #{count} item#{count == 1 ? '' : 's'}"
@apple.connect!
count.times do
@queue.pop do |notification|
begin
ohai "Sending notification for #{notification.token}"
APND.ohai "Sending notification for #{notification.token}"
@apple.write(notification.to_bytes)
rescue Errno::EPIPE, OpenSSL::SSL::SSLError
ohai "Error, notification has been added back to the queue"
APND.ohai "Error, notification has been added back to the queue"
@queue.push(notification)
@apple.reconnect!
rescue RuntimeError => error
ohai "Error: #{error}"
APND.ohai "Error: #{error}"
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/apnd/daemon/protocol.rb
Expand Up @@ -11,14 +11,14 @@ module Daemon::Protocol
#
def post_init
@address = ::Socket.unpack_sockaddr_in(self.get_peername)
ohai "#{@address.last}:#{@address.first} opened connection"
APND.ohai "#{@address.last}:#{@address.first} opened connection"
end

#
# Called when a client connection is closed
#
def unbind
ohai "#{@address.last}:#{@address.first} closed connection"
APND.ohai "#{@address.last}:#{@address.first} closed connection"
end

#
Expand All @@ -28,10 +28,10 @@ def receive_data(data)
(@buffer ||= "") << data
@buffer.each_line do |line|
if notification = APND::Notification.valid?(line)
ohai "#{@address.last}:#{@address.first} added new Notification to queue"
APND.ohai "#{@address.last}:#{@address.first} added new Notification to queue"
queue.push(notification)
else
ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
APND.ohai "#{@address.last}:#{@address.first} submitted invalid Notification"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Expand Up @@ -23,5 +23,5 @@ def queue

end

# Silence ohai in testing
def ohai(*args); end
# Silence APND.ohai in testing
def APND.ohai(*args); end

0 comments on commit 01973be

Please sign in to comment.