|
@ -156,7 +156,7 @@ class WebPushService(): |
|
|
except WebPushException as ex: |
|
|
except WebPushException as ex: |
|
|
now = datetime.datetime.now().isoformat() |
|
|
now = datetime.datetime.now().isoformat() |
|
|
endpoint = subscription_info['endpoint'] |
|
|
endpoint = subscription_info['endpoint'] |
|
|
print(f"{now}: Failed to send push notification for {endpoint} -- {ex}") |
|
|
print(f"{now}: Failed to send push notification for {endpoint} -- {ex}", flush=True) |
|
|
|
|
|
|
|
|
unsubscribed_msg = '410 Gone' |
|
|
unsubscribed_msg = '410 Gone' |
|
|
if unsubscribed_msg in ex.args[0]: |
|
|
if unsubscribed_msg in ex.args[0]: |
|
@ -166,11 +166,13 @@ class WebPushService(): |
|
|
if subscription: |
|
|
if subscription: |
|
|
db.session.delete(subscription) |
|
|
db.session.delete(subscription) |
|
|
db.session.commit() |
|
|
db.session.commit() |
|
|
print(f"Committed delete of {subscription_info}") |
|
|
print(f"Committed delete of {subscription_info}", flush=True) |
|
|
else: |
|
|
else: |
|
|
print(f"Could not find subscription at: {endpoint}") |
|
|
print(f"Could not find subscription at: {endpoint}", flush=True) |
|
|
else: |
|
|
else: |
|
|
print("Wrong error.", ex.args[0]) |
|
|
print("Error other than unsubscribed/expired.", ex.args[0], flush=True) |
|
|
|
|
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _send_daily_notifications(self) -> None: |
|
|
def _send_daily_notifications(self) -> None: |
|
@ -193,7 +195,7 @@ class WebPushService(): |
|
|
while True: |
|
|
while True: |
|
|
|
|
|
|
|
|
now = datetime.datetime.now().isoformat() |
|
|
now = datetime.datetime.now().isoformat() |
|
|
print(f"{now} - Starting to send subscriptions...") |
|
|
print(f"{now} - Starting to send subscriptions...", flush=True) |
|
|
|
|
|
|
|
|
# Creating a context for the application to enable database operations |
|
|
# Creating a context for the application to enable database operations |
|
|
with self.app.app_context(): |
|
|
with self.app.app_context(): |
|
@ -217,7 +219,7 @@ class WebPushService(): |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
WebPushService._send_push_notification(subscription_info, message, vapid_key) |
|
|
WebPushService._send_push_notification(subscription_info, message, vapid_key) |
|
|
print(f"{now} - Finished sending {len(all_subscriptions)} subscriptions.") |
|
|
print(f"{now} - Finished sending {len(all_subscriptions)} subscriptions.", flush=True) |
|
|
|
|
|
|
|
|
# Sleeping for 24 hours before sending the next set of notifications |
|
|
# Sleeping for 24 hours before sending the next set of notifications |
|
|
time.sleep(24 * 60 * 60) |
|
|
time.sleep(24 * 60 * 60) |
|
@ -406,4 +408,3 @@ class WebPushService(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web_push_service = WebPushService(app, "app") |
|
|
web_push_service = WebPushService(app, "app") |
|
|
|
|
|
|
|
|