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
22
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 15
def initialize(app)
@app = app
@host, @port = HOSTS[@app.environment.to_sym]
@poll = Rpush.config.feedback_poll
@certificate = app.certificate
@password = app.password
@interruptible_sleep = InterruptibleSleep.new
end
|
Instance Method Details
#check_for_feedback ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 44
def check_for_feedback
connection = nil
begin
connection = Rpush::Daemon::TcpConnection.new(@app, @host, @port)
connection.connect
while tuple = connection.read(TUPLE_BYTES)
timestamp, device_token = parse_tuple(tuple)
create_feedback(timestamp, device_token)
end
rescue StandardError => e
log_error(e)
reflect(:error, e)
ensure
connection.close if connection
end
end
|
#start ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 24
def start
return if Rpush.config.push
@thread = Thread.new do
loop do
break if @stop
check_for_feedback
@interruptible_sleep.sleep @poll
end
Rpush::Daemon.store.release_connection
end
end
|
#stop ⇒ Object
38
39
40
41
42
|
# File 'lib/rpush/daemon/apns/feedback_receiver.rb', line 38
def stop
@stop = true
@interruptible_sleep.interrupt_sleep
@thread.join if @thread
end
|