Skip to content

Commit

Permalink
switching to Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ponomarevlm committed Jul 20, 2009
1 parent 8659001 commit 4a49c22
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bin/sendserver.rb
Expand Up @@ -4,11 +4,12 @@
$: << File.expand_path(File.dirname(__FILE__))+'/../'
['rubygems', 'eventmachine', 'base64', 'lib/sender', 'lib/apncore', 'env/config'].each{|lib| require lib}

$logger = Logger.new("#{File.expand_path(File.dirname(__FILE__))}/../log/sendserver.log", 10, 1024000)
# properly close all connections and sokets
def stop
APNs4r::Sender.closeConnection
EventMachine::stop_server $server
puts "#{Time.now.to_s} SendServer stopped"
$logger.info "SendServer stopped"
exit
end
Signal.trap("TERM") {stop}
Expand All @@ -17,19 +18,19 @@ def stop

module SendServer
def post_init
puts "-- #{Time.now.to_s} -- Incoming connection"
$logger.info "Incoming connection"
end

def receive_data data
# TODO store notifications for later batch transmission
# only when some scaling needed
notification = Marshal.load( Base64.decode64(data))
APNs4r::Sender.send notification
puts "#{Time.now.to_s} #{notification.payload}"
$logger.info notification.payload}
end

def unbind
puts "-- #{Time.now.to_s} -- Connection closed"
$logger.info "Connection closed"
end
end

Expand All @@ -42,10 +43,10 @@ def unbind
:payload_length => p.payload_length, :device_token => OPTIONS[:ping_device_token]
APNs4r::Sender.send notification
end
puts "#{Time.now.to_s} SendServer started"
$logger.info "SendServer started"
$server = EventMachine::start_server OPTIONS[:sendserver_ip], OPTIONS[:sendserver_port], SendServer
else
puts "#{Time.now.to_s} SendServer: failed to connect to APNs: timeout"
$logger.error "SendServer: failed to connect to APNs: timeout"
exit 1
end
}

0 comments on commit 4a49c22

Please sign in to comment.