Class: Resque::Plugins::Aps::Feedback
- Inherits:
-
Object
- Object
- Resque::Plugins::Aps::Feedback
- Extended by:
- Helper
- Includes:
- Helper
- Defined in:
- lib/resque/plugins/aps/feedback.rb
Instance Attribute Summary collapse
-
#application_name ⇒ Object
Returns the value of attribute application_name.
-
#device_token ⇒ Object
Returns the value of attribute device_token.
-
#received_at ⇒ Object
Returns the value of attribute received_at.
Class Method Summary collapse
-
.perform(*args) ⇒ Object
Perform a Feedback check on the APN server, for the given app key (which must be the first argument).
- .read_feedback(ssl_socket, application_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Feedback
constructor
A new instance of Feedback.
- #inspect ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Helper
Constructor Details
#initialize(attributes) ⇒ Feedback
Returns a new instance of Feedback.
14 15 16 17 18 |
# File 'lib/resque/plugins/aps/feedback.rb', line 14 def initialize(attributes) attributes.each do |k, v| respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(Resque::Plugins::Aps::UnknownAttributeError, "unknown attribute: #{k}") end end |
Instance Attribute Details
#application_name ⇒ Object
Returns the value of attribute application_name.
12 13 14 |
# File 'lib/resque/plugins/aps/feedback.rb', line 12 def application_name @application_name end |
#device_token ⇒ Object
Returns the value of attribute device_token.
12 13 14 |
# File 'lib/resque/plugins/aps/feedback.rb', line 12 def device_token @device_token end |
#received_at ⇒ Object
Returns the value of attribute received_at.
12 13 14 |
# File 'lib/resque/plugins/aps/feedback.rb', line 12 def received_at @received_at end |
Class Method Details
.perform(*args) ⇒ Object
Perform a Feedback check on the APN server, for the given app key (which must be the first argument)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/resque/plugins/aps/feedback.rb', line 58 def self.perform(*args) app_name = args[0] start = Time.now count = 0 appl = Resque.aps_application(app_name) return unless appl appl.socket(nil, nil, Resque.aps_feedback_host, Resque.aps_feedback_port) do |socket, app| begin logger.debug("Feedback: Reading feedbacks for #{app_name}.") if logger timeout(5) do until socket.eof? app.before_aps_read feedback = read_feedback(socket, app_name) if feedback count += 1 app.after_aps_read(feedback) else app.aps_read_failed end end end rescue logger.error Application.application_exception($!, app_name) if logger app.aps_read_error(Application.application_exception($!, app_name)) end end logger.info("Read #{count} #{app_name} feedbacks over #{Time.now - start} sec.") if logger end |
.read_feedback(ssl_socket, application_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/resque/plugins/aps/feedback.rb', line 32 def self.read_feedback(ssl_socket, application_name) data_str = ssl_socket.read(4) return nil unless data_str data_ary = data_str.unpack('N') return nil unless data_ary && data_ary[0] time = Time.at(data_ary[0]) data_str = ssl_socket.read(2) return nil unless data_str data_ary = data_str.unpack('n') return nil unless data_ary && data_ary[0] tl = data_ary[0] data_str = ssl_socket.read(tl) return nil unless data_str data_ary = data_str.unpack('H*') return nil unless data_ary && data_ary[0] token = data_ary[0] feedback = Feedback.new({:received_at => time, :device_token => token, :application_name => application_name}) return feedback end |
Instance Method Details
#inspect ⇒ Object
20 21 22 |
# File 'lib/resque/plugins/aps/feedback.rb', line 20 def inspect "#<#{self.class.name} #{application_name.inspect}, #{device_token.inspect}, #{received_at.inspect}>" end |
#to_hash ⇒ Object
28 29 30 |
# File 'lib/resque/plugins/aps/feedback.rb', line 28 def to_hash {:application_name => application_name, :device_token => device_token, :received_at => received_at} end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/resque/plugins/aps/feedback.rb', line 24 def to_s "#{application_name} #{received_at} #{device_token}" end |