def platform_response(self, exception, notification_payload):
        """
            ## Trying to fix rate-limit or service down by retrying.
            ## After max of retries are exceeded we will log the payload
        """
        exception_code = exception.code
        exception_message = exception.msg

        remaining_retries = \
            notification_payload.get("remaining_retries", settings.NOTIFICATION_SENDING_MAX_TRIES + 1) - 1
        logged = notification_payload.get("logged", False)

        if exception_code in TwilioExceptionsCodes.RATE_LIMIT_LIST_CODES_EXCEPTION and remaining_retries > 0:
            self.message_queue_dep.send(message=notification_payload)
        elif not logged:
            notification_payload.update({
                "exception_code": exception_code,
                "exception_message": exception_message,
                "logged": True
            })
            notification_payload.pop("_id", None)
            storage_service = StorageService()
            storage_service.insert_failure(doc_data=notification_payload)
Exemple #2
0
    def platform_response(self, exception, notification_payload):
        """
            # TODO check FCM exceptions to differentiate between
                ## Exceptions that we need to log it for monitoring
                ## Exceptions such as rate-limit or service down to retry.
        """
        remaining_retries = \
            notification_payload.get("remaining_retries", settings.NOTIFICATION_SENDING_MAX_TRIES + 1) - 1
        logged = notification_payload.get("logged", False)

        notification_payload.update({
            "exception_message": exception.__repr__(),
            "remaining_retries": remaining_retries,
            "logged": logged
        })

        if remaining_retries == 0:
            notification_payload.pop("_id", None)
            storage_service = StorageService()
            storage_service.insert_failure(doc_data=notification_payload)
            notification_payload.update({"logged": True})

        if remaining_retries > 0:
            self.message_queue_dep.send(message=notification_payload)