apn_sender 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apn_sender.gemspec +2 -2
- data/generators/{apple_push_notification_generator.rb → apn_sender_generator.rb} +1 -1
- data/generators/templates/script +4 -1
- data/lib/apn/connection/base.rb +18 -7
- data/lib/apn/feedback.rb +1 -1
- data/lib/apn/sender.rb +1 -1
- data/lib/apn/sender_daemon.rb +22 -11
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/apn_sender.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{apn_sender}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kali Donovan"]
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"apn_sender.gemspec",
|
27
27
|
"contrib/apn_sender.monitrc",
|
28
|
-
"generators/
|
28
|
+
"generators/apn_sender_generator.rb",
|
29
29
|
"generators/templates/script",
|
30
30
|
"init.rb",
|
31
31
|
"lib/apn.rb",
|
data/generators/templates/script
CHANGED
@@ -3,5 +3,8 @@
|
|
3
3
|
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
|
4
4
|
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'rubygems'
|
7
|
+
require 'apn'
|
8
|
+
require 'apn/sender_daemon'
|
9
|
+
|
7
10
|
APN::SenderDaemon.new(ARGV).daemonize
|
data/lib/apn/connection/base.rb
CHANGED
@@ -11,7 +11,7 @@ module APN
|
|
11
11
|
@opts = opts
|
12
12
|
|
13
13
|
setup_logger
|
14
|
-
|
14
|
+
log(:info, "APN::Sender initializing. Establishing connections first...") if @opts[:verbose]
|
15
15
|
setup_paths
|
16
16
|
|
17
17
|
super( APN::QUEUE_NAME ) if self.class.ancestors.include?(Resque::Worker)
|
@@ -33,8 +33,19 @@ module APN
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
# Log message to any logger provided by the user (e.g. the Rails logger).
|
37
|
+
# Accepts +log_level+, +message+, since that seems to make the most sense,
|
38
|
+
# and just +message+, to be compatible with Resque's log method and to enable
|
39
|
+
# sending verbose and very_verbose worker messages to e.g. the rails logger.#
|
40
|
+
#
|
41
|
+
# Perhaps a method definition of +message, +level+ would make more sense, but
|
42
|
+
# that's also the complete opposite of what anyone comming from rails would expect.
|
43
|
+
alias_method(:resque_log, :log) if defined?(log)
|
44
|
+
def log(level, message = nil)
|
45
|
+
level, message = 'info', level if message.nil? # Handle only one argument if called from Resque, which expects only message
|
46
|
+
|
47
|
+
resque_log(message) if defined?(resque_log)
|
48
|
+
return false unless self.logger && self.logger.respond_to?(level)
|
38
49
|
self.logger.send(level, "#{Time.now}: #{message}")
|
39
50
|
end
|
40
51
|
|
@@ -71,24 +82,24 @@ module APN
|
|
71
82
|
@socket.sync = true
|
72
83
|
@socket.connect
|
73
84
|
rescue SocketError => error
|
74
|
-
|
85
|
+
log(:error, "Error with connection to #{apn_host}: #{error}")
|
75
86
|
raise "Error with connection to #{apn_host}: #{error}"
|
76
87
|
end
|
77
88
|
|
78
89
|
# Close open sockets
|
79
90
|
def teardown_connection
|
80
|
-
|
91
|
+
log(:info, "Closing connections...") if @opts[:verbose]
|
81
92
|
|
82
93
|
begin
|
83
94
|
@socket.close if @socket
|
84
95
|
rescue Exception => e
|
85
|
-
|
96
|
+
log(:error, "Error closing SSL Socket: #{e}")
|
86
97
|
end
|
87
98
|
|
88
99
|
begin
|
89
100
|
@socket_tcp.close if @socket_tcp
|
90
101
|
rescue Exception => e
|
91
|
-
|
102
|
+
log(:error, "Error closing TCP Socket: #{e}")
|
92
103
|
end
|
93
104
|
end
|
94
105
|
|
data/lib/apn/feedback.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'apn/connection/base'
|
2
2
|
|
3
3
|
module APN
|
4
4
|
# Encapsulates data returned from the {APN Feedback Service}[http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3].
|
data/lib/apn/sender.rb
CHANGED
@@ -24,7 +24,7 @@ module APN
|
|
24
24
|
|
25
25
|
self.socket.write( notification.to_s )
|
26
26
|
rescue SocketError => error
|
27
|
-
|
27
|
+
log(:error, "Error with connection to #{apn_host} (attempt #{attempt}): #{error}")
|
28
28
|
|
29
29
|
# Try reestablishing the connection
|
30
30
|
teardown_connection
|
data/lib/apn/sender_daemon.rb
CHANGED
@@ -5,11 +5,9 @@ require 'optparse'
|
|
5
5
|
|
6
6
|
module APN
|
7
7
|
class SenderDaemon
|
8
|
-
attr_accessor :worker_count
|
9
8
|
|
10
9
|
def initialize(args)
|
11
|
-
@options = {:quiet => true}
|
12
|
-
@worker_count = 1
|
10
|
+
@options = {:quiet => true, :worker_count => 1, :environment => :development}
|
13
11
|
|
14
12
|
opts = OptionParser.new do |opts|
|
15
13
|
opts.banner = "Usage: #{File.basename($0)} [options] start|stop|restart|run"
|
@@ -24,16 +22,29 @@ module APN
|
|
24
22
|
opts.on('--cert-path=NAME', '--certificate-path=NAME', 'Path to directory containing apn .pem certificates.') do |path|
|
25
23
|
@options[:cert_path] = path
|
26
24
|
end
|
27
|
-
opts.on('-n', '--number_of_workers=
|
28
|
-
@worker_count = worker_count.to_i rescue 1
|
25
|
+
opts.on('-n', '--number_of_workers=WORKERS', "Number of unique workers to spawn") do |worker_count|
|
26
|
+
@options[:worker_count] = worker_count.to_i rescue 1
|
27
|
+
end
|
28
|
+
opts.on('-v', '--verbose', "Turn on verbose mode") do
|
29
|
+
@options[:verbose] = true
|
30
|
+
end
|
31
|
+
opts.on('-V', '--very_verbose', "Turn on very verbose mode") do
|
32
|
+
@options[:very_verbose] = true
|
33
|
+
end
|
34
|
+
opts.on('-d', '--delay=D', "Delay between rounds of work (seconds)") do |d|
|
35
|
+
@options[:delay] = d
|
29
36
|
end
|
30
37
|
end
|
31
|
-
|
38
|
+
|
39
|
+
# If no arguments, give help screen
|
40
|
+
@args = optparse.parse!(args.empty? ? ['-h'] : args)
|
41
|
+
|
42
|
+
puts "OPTS: #{@options.inspect}"
|
32
43
|
end
|
33
44
|
|
34
45
|
def daemonize
|
35
|
-
worker_count.times do |worker_index|
|
36
|
-
process_name = worker_count == 1 ? "apn_sender" : "apn_sender.#{worker_index}"
|
46
|
+
@options[:worker_count].times do |worker_index|
|
47
|
+
process_name = @options[:worker_count] == 1 ? "apn_sender" : "apn_sender.#{worker_index}"
|
37
48
|
Daemons.run_proc(process_name, :dir => "#{::RAILS_ROOT}/tmp/pids", :dir_mode => :normal, :ARGV => @args) do |*args|
|
38
49
|
run process_name
|
39
50
|
end
|
@@ -49,14 +60,14 @@ module APN
|
|
49
60
|
logger.level = ActiveRecord::Base.logger.level
|
50
61
|
ActiveRecord::Base.logger = logger
|
51
62
|
ActiveRecord::Base.clear_active_connections!
|
52
|
-
APN::Sender.logger = logger
|
53
63
|
|
54
64
|
worker = APN::Sender.new(@options)
|
65
|
+
worker.logger = logger
|
55
66
|
worker.verbose = @options[:verbose]
|
56
67
|
worker.very_verbose = @options[:very_verbose]
|
57
|
-
worker.work(@options[:delay]
|
68
|
+
worker.work(@options[:delay])
|
58
69
|
rescue => e
|
59
|
-
logger.fatal
|
70
|
+
logger.fatal(e) if logger.respond_to?(:fatal)
|
60
71
|
STDERR.puts e.message
|
61
72
|
exit 1
|
62
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apn_sender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kali Donovan
|
@@ -50,7 +50,7 @@ files:
|
|
50
50
|
- VERSION
|
51
51
|
- apn_sender.gemspec
|
52
52
|
- contrib/apn_sender.monitrc
|
53
|
-
- generators/
|
53
|
+
- generators/apn_sender_generator.rb
|
54
54
|
- generators/templates/script
|
55
55
|
- init.rb
|
56
56
|
- lib/apn.rb
|