Vortex: add ApnsPHP dispatcher

Review Request #446 — Created May 26, 2016 and submitted

tardypad
Lunr
apns_php_dispatcher
447
lunr

The new ApnsPHP is pretty annoying to work with inside our notification structure in the end...
see http://reviews.lunr.nl/r/447/ as well for the response class

It's not straightforward to define the status of the push for each endpoint:
- the library only returns an error structure (in a weird format...) for the endpoints with a failure
- some invalid endpoints are detected early on before the push and we don't get them as part of this report (because they are detected in a different Message class)
- we can then assume that the notification was delivered successfully to the endpoints left

unit tests

  • 0
  • 0
  • 3
  • 0
  • 3
Description From Last Updated
tardypad
pprkut
  1. Re Logging, it might be worth switching ApnsPHP over to PSR-3.
    Their logger interface is more or less compatible already.

    1. I'm fine with moving ApnsPHP to PSR-3 but I'm not sure it will be that useful.
      Here below is an example of all that the library is logging internally for a sending to only 14 endpoints, including a few invalid ones.

      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Trying tls://gateway.push.apple.com:2195...
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Connected to tls://gateway.push.apple.com:2195.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Sending messages queue, run #1: 14 message(s) left in queue.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 1 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 2 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 3 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 4 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 5 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 6 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 7 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 8 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 9 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 10 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 11 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 12 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 13 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 14 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: ERROR: Unable to send message ID 1: Invalid token (8).
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Disconnected.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Trying tls://gateway.push.apple.com:2195...
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Connected to tls://gateway.push.apple.com:2195.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: INFO: Sending messages queue, run #2: 14 message(s) left in queue.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: WARNING: Message ID 1 [custom identifier: unset] has an unrecoverable error (8), removing from queue without retrying...
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 2 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 3 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 4 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 5 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 6 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:27 +0200 ApnsPHP[24063]: STATUS: Sending message ID 7 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 8 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 9 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 10 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 11 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 12 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 13 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 14 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: ERROR: Unable to send message ID 13: Invalid token (8).
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: INFO: Disconnected.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: INFO: Trying tls://gateway.push.apple.com:2195...
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: INFO: Connected to tls://gateway.push.apple.com:2195.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: INFO: Sending messages queue, run #3: 2 message(s) left in queue.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: WARNING: Message ID 13 [custom identifier: unset] has an unrecoverable error (8), removing from queue without retrying...
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: STATUS: Sending message ID 14 [custom identifier: unset] (1/3): 80 bytes.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: ERROR: Unable to send message ID 14: Invalid token (8).
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: INFO: Disconnected.
      Tue, 14 Jun 2016 13:27:28 +0200 ApnsPHP[24063]: INFO: Trying tls://gateway.push.apple.com:2195...
      Tue, 14 Jun 2016 13:27:29 +0200 ApnsPHP[24063]: INFO: Connected to tls://gateway.push.apple.com:2195.
      Tue, 14 Jun 2016 13:27:29 +0200 ApnsPHP[24063]: INFO: Sending messages queue, run #4: 1 message(s) left in queue.
      Tue, 14 Jun 2016 13:27:29 +0200 ApnsPHP[24063]: WARNING: Message ID 14 [custom identifier: unset] has an unrecoverable error (8), removing from queue without retrying...
      Tue, 14 Jun 2016 13:27:30 +0200 ApnsPHP[24063]: INFO: Disconnected.
      

      Now I am not sure we really want all this when sending to a few thousands of them.
      What would be more useful would be a way to disable their logging altogether, and just use ours build around.
      Or if we implement PSR-3, we would need a way to specify the log level we want to have.

    2. But implementing PSR-3 would give us exactly that option right? To specify a loglevel?

    3. Not directly I think.

      It would remove the need for their own interface https://github.com/immobiliare/ApnsPHP/blob/master/ApnsPHP/Log/Interface.php
      and it would replace their calls $this->_log('ERROR: Unable to send message ID) by $this->_log->error('Unable to send message ID) for example.
      But all those individual loggings would still be there in the library.
      There is nothing there that would say "Only log starting from the error level".

      This behavior would need to be implemented afterwards within the library itself or within the logger we would provide

    4. Typically this is implemented in the logger. It's not zero-cost then, but depending on how it's implemented it might be close to it.
      We could for example easily write a FilterLogger for Lunr that just ignores errors of certain levels (we can't do stuff like $level > NOTICE though, thank you PSR-3!). Application developers could then even selectively use that FilterLogger only for ApnsPHP (by means of our ServiceLocator or some similar such).
      There is also the choice of Monolog's FilterHandler, which would essentially do the same thing, but I don't know enough about that one.

    5. Yes I was thinking of something like this

      The question is: do we need any of the log that are there?
      I don't see anything more useful than what we would log ourselves in the dispatcher and response classes
      In that case, it would be simpler to just add a functionnality to disable the logging.

    6. With PSR-3 we'd already have that. We could use our NullLogger to just ignore all log messages.

    7. Indeed I didn't think of this one
      Well I guess, we need to go for implementing PSR3 there then

  2. src/Lunr/Vortex/APNS/ApnsPHP/APNSDispatcher.php (Diff revision 2)
     
     
     
     

    Not necessarily. It's a bit ugly since we have to honor Dependency Injection, but rather then pass the Message object in the constructor, we can re-instantiate a new one on every call to push().

    We can do this by implementing a get_new_apns_message() method that returns the object. That way we can mock it (sort of).

  3. 
      
tardypad
tardypad
tardypad
pprkut
  1. 
      
  2. I'd prefer use statements on top rather than absolute references in the code. Makes it slightly easier to see external dependencies.

  3. src/Lunr/Vortex/APNS/ApnsPHP/APNSDispatcher.php (Diff revision 5)
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    why do we need this?

    I'd say this has no business here. The user can configure ApnsPHP however he/she wants before (or even after) passing it to the constructor of this class.

  4. 
      
tardypad
tardypad
Review request changed

Status: Closed (submitted)

Change Summary:

Merged into master

Loading...