Skip to content

Webpushes timeout #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY

- ``WP_PRIVATE_KEY``: Absolute path to your private certificate file: os.path.join(BASE_DIR, "private_key.pem")
- ``WP_CLAIMS``: Dictionary with default value for the sub, (subject), sent to the webpush service, This would be used by the service if they needed to reach out to you (the sender). Could be a url or mailto e.g. {'sub': "mailto:development@example.com"}.
- ``WP_ERROR_TIMEOUT``: The timeout on WebPush POSTs. (Optional)
- ``WP_ERROR_TIMEOUT``: The timeout on WebPush POSTs. (Optional, default value is 1 second)

For more information about how to configure WebPush, see `docs/WebPush <https://github.com/jazzband/django-push-notifications/blob/master/docs/WebPush.rst>`_.

Expand Down
4 changes: 4 additions & 0 deletions push_notifications/conf/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def _validate_wp_config(self, application_id, application_config):
"EDGE": "https://wns2-par02p.notify.windows.com/w",
"FIREFOX": "https://updates.push.services.mozilla.com/wpush/v2",
})
application_config.setdefault("ERROR_TIMEOUT", 1)

def _validate_allowed_settings(self, application_id, application_config, allowed_settings):
"""Confirm only allowed settings are present."""
Expand Down Expand Up @@ -349,3 +350,6 @@ def get_wp_private_key(self, application_id=None):

def get_wp_claims(self, application_id=None):
return self._get_application_settings(application_id, "WP", "CLAIMS")

def get_wp_error_timeout(self, application_id=None):
return self._get_application_settings(application_id, "WP", "ERROR_TIMEOUT")
4 changes: 4 additions & 0 deletions push_notifications/conf/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ def get_wp_private_key(self, application_id=None):
def get_wp_claims(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "WP_CLAIMS", msg)

def get_wp_error_timeout(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to set a timeout"
return self._get_application_settings(application_id, "WP_ERROR_TIMEOUT", msg)
2 changes: 1 addition & 1 deletion push_notifications/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
})
PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_PRIVATE_KEY", None)
PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_CLAIMS", None)
PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_ERROR_TIMEOUT", None)
PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_ERROR_TIMEOUT", 1)

# User model
PUSH_NOTIFICATIONS_SETTINGS.setdefault("USER_MODEL", settings.AUTH_USER_MODEL)
Expand Down
1 change: 1 addition & 0 deletions push_notifications/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def webpush_send_message(device, message, **kwargs):
data=message,
vapid_private_key=get_manager().get_wp_private_key(device.application_id),
vapid_claims=get_manager().get_wp_claims(device.application_id).copy(),
timeout=get_manager().get_wp_error_timeout(device.application_id),
**kwargs
)
if response.ok:
Expand Down
Loading