forked from rDrama/rDrama
Dispatch push notifications using greenlets.
parent
7a37f9f865
commit
9b09181e28
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
|
||||||
|
import gevent
|
||||||
from flask import g
|
from flask import g
|
||||||
from pywebpush import webpush
|
from pywebpush import webpush
|
||||||
|
|
||||||
|
@ -114,9 +115,14 @@ def push_notif(uid, title, body, url):
|
||||||
|
|
||||||
subscriptions = g.db.query(PushSubscription).filter_by(user_id=uid).all()
|
subscriptions = g.db.query(PushSubscription).filter_by(user_id=uid).all()
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
|
gevent.spawn(_push_notif_thread,
|
||||||
|
subscription.subscription_json, title, body, url)
|
||||||
|
|
||||||
|
|
||||||
|
def _push_notif_thread(sub_json, title, body, url):
|
||||||
try:
|
try:
|
||||||
response = webpush(
|
response = webpush(
|
||||||
subscription_info=json.loads(subscription.subscription_json),
|
subscription_info=json.loads(sub_json),
|
||||||
data=json.dumps({
|
data=json.dumps({
|
||||||
"title": title,
|
"title": title,
|
||||||
"body": body,
|
"body": body,
|
||||||
|
@ -126,4 +132,4 @@ def push_notif(uid, title, body, url):
|
||||||
vapid_private_key=VAPID_PRIVATE_KEY,
|
vapid_private_key=VAPID_PRIVATE_KEY,
|
||||||
vapid_claims={"sub": f"mailto:{EMAIL}"}
|
vapid_claims={"sub": f"mailto:{EMAIL}"}
|
||||||
)
|
)
|
||||||
except: continue
|
except: pass
|
||||||
|
|
Loading…
Reference in New Issue