Skip to content

Commit 00f8645

Browse files
committed
Merge branch 'apns-timeout' into master-3.2.1-with-custom
2 parents ffa87e7 + 65165ee commit 00f8645

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY
114114
- ``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.
115115
- ``APNS_USE_ALTERNATIVE_PORT``: Use port 2197 for APNS, instead of default port 443.
116116
- ``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.
117+
- ``APNS_ERROR_TIMEOUT``: The timeout on APNS requests. (Optional, default value is 1 second)
117118

118119
**FCM/GCM settings**
119120

push_notifications/apns_async.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def apns_send_bulk_message(
317317
"""
318318
try:
319319
topic = get_manager().get_apns_topic(application_id)
320+
timeout = get_manager().get_apns_error_timeout(application_id)
320321
results: Dict[str, str] = {}
321322
inactive_tokens = []
322323

@@ -339,6 +340,7 @@ def apns_send_bulk_message(
339340
mutable_content=mutable_content,
340341
category=category,
341342
err_func=err_func,
343+
timeout=timeout,
342344
)
343345
)
344346

@@ -390,6 +392,7 @@ async def _send_bulk_request(
390392
mutable_content: bool = False,
391393
category: str = None,
392394
err_func: ErrFunc = None,
395+
timeout: float = None,
393396
):
394397
client = _create_client(
395398
creds=creds, application_id=application_id, topic=topic, err_func=err_func
@@ -420,13 +423,13 @@ async def _send_bulk_request(
420423
for registration_id in registration_ids
421424
]
422425

423-
send_requests = [_send_request(client, request) for request in requests]
426+
send_requests = [_send_request(client, request, timeout) for request in requests]
424427
return await asyncio.gather(*send_requests)
425428

426429

427-
async def _send_request(apns, request):
430+
async def _send_request(apns, request, timeout):
428431
try:
429-
res = await asyncio.wait_for(apns.send_notification(request), timeout=1)
432+
res = await asyncio.wait_for(apns.send_notification(request), timeout=timeout)
430433
return request.device_token, res
431434
except asyncio.TimeoutError:
432435
return request.device_token, NotificationResult(

push_notifications/conf/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
APNS_AUTH_CREDS_OPTIONAL = ["CERTIFICATE", "ENCRYPTION_ALGORITHM", "TOKEN_LIFETIME"]
5252

5353
APNS_OPTIONAL_SETTINGS = [
54-
"USE_SANDBOX", "USE_ALTERNATIVE_PORT", "TOPIC"
54+
"USE_SANDBOX", "USE_ALTERNATIVE_PORT", "TOPIC", "ERROR_TIMEOUT"
5555
]
5656

5757
FCM_REQUIRED_SETTINGS = []
@@ -165,6 +165,7 @@ def _validate_apns_config(self, application_id, application_config):
165165
application_config.setdefault("USE_SANDBOX", False)
166166
application_config.setdefault("USE_ALTERNATIVE_PORT", False)
167167
application_config.setdefault("TOPIC", None)
168+
application_config.setdefault("ERROR_TIMEOUT", 1)
168169

169170
def _validate_apns_certificate(self, certfile):
170171
"""Validate the APNS certificate at startup."""
@@ -335,6 +336,9 @@ def get_apns_use_alternative_port(self, application_id=None):
335336
def get_apns_topic(self, application_id=None):
336337
return self._get_application_settings(application_id, "APNS", "TOPIC")
337338

339+
def get_apns_error_timeout(self, application_id=None):
340+
return self._get_application_settings(application_id, "APNS", "ERROR_TIMEOUT")
341+
338342
def get_wns_package_security_id(self, application_id=None):
339343
return self._get_application_settings(application_id, "WNS", "PACKAGE_SECURITY_ID")
340344

push_notifications/conf/legacy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def get_apns_feedback_host(self, application_id=None):
110110
def get_apns_feedback_port(self, application_id=None):
111111
return self._get_application_settings(application_id, "APNS_FEEDBACK_PORT", self.msg)
112112

113+
def get_apns_error_timeout(self, application_id=None):
114+
return self._get_application_settings(application_id, "APNS_ERROR_TIMEOUT")
115+
113116
def get_wns_package_security_id(self, application_id=None):
114117
return self._get_application_settings(application_id, "WNS_PACKAGE_SECURITY_ID", self.msg)
115118

push_notifications/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_USE_SANDBOX", False)
1919
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_USE_ALTERNATIVE_PORT", False)
2020
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_TOPIC", None)
21+
PUSH_NOTIFICATIONS_SETTINGS.setdefault("APNS_ERROR_TIMEOUT", 1)
2122

2223
# WNS
2324
PUSH_NOTIFICATIONS_SETTINGS.setdefault("WNS_PACKAGE_SECURITY_ID", None)

0 commit comments

Comments
 (0)