Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY
- ``APNS_TOPIC``: The topic of the remote notification, which is typically the bundle ID for your app. If you omit this header and your APNs certificate does not specify multiple topics, the APNs server uses the certificate’s Subject as the default topic.
- ``APNS_USE_ALTERNATIVE_PORT``: Use port 2197 for APNS, instead of default port 443.
- ``APNS_USE_SANDBOX``: Use 'api.development.push.apple.com', instead of default host 'api.push.apple.com'. Default value depends on ``DEBUG`` setting of your environment: if ``DEBUG`` is True and you use production certificate, you should explicitly set ``APNS_USE_SANDBOX`` to False.
- ``APNS_ERROR_TIMEOUT``: The timeout on APNS requests. (Optional, default value is 1 second)

**FCM/GCM settings**

Expand Down
9 changes: 6 additions & 3 deletions push_notifications/apns_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def apns_send_bulk_message(
"""
try:
topic = get_manager().get_apns_topic(application_id)
timeout = get_manager().get_apns_error_timeout(application_id)
results: Dict[str, str] = {}
inactive_tokens = []

Expand All @@ -339,6 +340,7 @@ def apns_send_bulk_message(
mutable_content=mutable_content,
category=category,
err_func=err_func,
timeout=timeout,
)
)

Expand Down Expand Up @@ -390,6 +392,7 @@ async def _send_bulk_request(
mutable_content: bool = False,
category: str = None,
err_func: ErrFunc = None,
timeout: float = None,
):
client = _create_client(
creds=creds, application_id=application_id, topic=topic, err_func=err_func
Expand Down Expand Up @@ -420,13 +423,13 @@ async def _send_bulk_request(
for registration_id in registration_ids
]

send_requests = [_send_request(client, request) for request in requests]
send_requests = [_send_request(client, request, timeout) for request in requests]
return await asyncio.gather(*send_requests)


async def _send_request(apns, request):
async def _send_request(apns, request, timeout):
try:
res = await asyncio.wait_for(apns.send_notification(request), timeout=1)
res = await asyncio.wait_for(apns.send_notification(request), timeout=timeout)
return request.device_token, res
except asyncio.TimeoutError:
return request.device_token, NotificationResult(
Expand Down
6 changes: 5 additions & 1 deletion push_notifications/conf/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
APNS_AUTH_CREDS_OPTIONAL = ["CERTIFICATE", "ENCRYPTION_ALGORITHM", "TOKEN_LIFETIME"]

APNS_OPTIONAL_SETTINGS = [
"USE_SANDBOX", "USE_ALTERNATIVE_PORT", "TOPIC"
"USE_SANDBOX", "USE_ALTERNATIVE_PORT", "TOPIC", "ERROR_TIMEOUT"
]

FCM_REQUIRED_SETTINGS = []
Expand Down Expand Up @@ -165,6 +165,7 @@ def _validate_apns_config(self, application_id, application_config):
application_config.setdefault("USE_SANDBOX", False)
application_config.setdefault("USE_ALTERNATIVE_PORT", False)
application_config.setdefault("TOPIC", None)
application_config.setdefault("ERROR_TIMEOUT", 1)

def _validate_apns_certificate(self, certfile):
"""Validate the APNS certificate at startup."""
Expand Down Expand Up @@ -335,6 +336,9 @@ def get_apns_use_alternative_port(self, application_id=None):
def get_apns_topic(self, application_id=None):
return self._get_application_settings(application_id, "APNS", "TOPIC")

def get_apns_error_timeout(self, application_id=None):
return self._get_application_settings(application_id, "APNS", "ERROR_TIMEOUT")

def get_wns_package_security_id(self, application_id=None):
return self._get_application_settings(application_id, "WNS", "PACKAGE_SECURITY_ID")

Expand Down
3 changes: 3 additions & 0 deletions push_notifications/conf/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def get_apns_feedback_host(self, application_id=None):
def get_apns_feedback_port(self, application_id=None):
return self._get_application_settings(application_id, "APNS_FEEDBACK_PORT", self.msg)

def get_apns_error_timeout(self, application_id=None):
return self._get_application_settings(application_id, "APNS_ERROR_TIMEOUT")

def get_wns_package_security_id(self, application_id=None):
return self._get_application_settings(application_id, "WNS_PACKAGE_SECURITY_ID", self.msg)

Expand Down
1 change: 1 addition & 0 deletions push_notifications/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_USE_SANDBOX", False)
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_USE_ALTERNATIVE_PORT", False)
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_TOPIC", None)
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_ERROR_TIMEOUT", 1)

# WNS
PUSH_NOTIFICATIONS_SETTINGS.setdefault("WNS_PACKAGE_SECURITY_ID", None)
Expand Down
Loading