Class: Rpush::Daemon::Apns::FeedbackReceiver
- Inherits:
-
Object
- Object
- Rpush::Daemon::Apns::FeedbackReceiver
show all
- Includes:
- Loggable, Reflectable
- Defined in:
- lib/rpush/daemon/apns/feedback_receiver.rb
Constant Summary
collapse
- TUPLE_BYTES =
38
- HOSTS =
{
production: ['feedback.push.apple.com', 2196],
development: ['feedback.sandbox.push.apple.com', 2196], sandbox: ['feedback.sandbox.push.apple.com', 2196]
}
Instance Method Summary
collapse
Methods included from Loggable
#log_error, #log_info, #log_warn
#reflect
Constructor Details
Returns a new instance of FeedbackReceiver.
15
16
17
18
19
20
21
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 15
def initialize(app)
@app = app
@host, @port = HOSTS[@app.environment.to_sym]
@certificate = app.certificate
@password = app.password
@interruptible_sleep = InterruptibleSleep.new(Rpush.config.feedback_poll)
end
|
Instance Method Details
#check_for_feedback ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 45
def check_for_feedback
connection = nil
begin
connection = Rpush::Daemon::TcpConnection.new(@app, @host, @port)
connection.connect
tuple = connection.read(TUPLE_BYTES)
while tuple
timestamp, device_token = parse_tuple(tuple)
create_feedback(timestamp, device_token)
tuple = connection.read(TUPLE_BYTES)
end
rescue StandardError => e
log_error(e)
reflect(:error, e)
ensure
connection.close if connection
end
end
|
#start ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 23
def start
return if Rpush.config.push
log_info("APNs Feedback Receiver started.")
@interruptible_sleep.start
@thread = Thread.new do
loop do
break if @stop
check_for_feedback
@interruptible_sleep.sleep
end
Rpush::Daemon.store.release_connection
end
end
|
#stop ⇒ Object
39
40
41
42
43
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 39
def stop
@stop = true
@interruptible_sleep.stop
@thread.join if @thread
end
|