mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 04:48:06 +00:00
address typo-level review comments
This commit is contained in:
@@ -34,10 +34,8 @@ class Metadata:
|
|||||||
|
|
||||||
def add_token_to_addr(self, addr, token):
|
def add_token_to_addr(self, addr, token):
|
||||||
with self.get_metadata_dict(addr).modify() as data:
|
with self.get_metadata_dict(addr).modify() as data:
|
||||||
tokens = data.get(self.DEVICETOKEN_KEY)
|
tokens = data.setdefault(self.DEVICETOKEN_KEY, [])
|
||||||
if tokens is None:
|
if token not in tokens:
|
||||||
data[self.DEVICETOKEN_KEY] = [token]
|
|
||||||
elif token not in tokens:
|
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
|
|
||||||
def remove_token_from_addr(self, addr, token):
|
def remove_token_from_addr(self, addr, token):
|
||||||
@@ -130,8 +128,7 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
notification_dir = vmail_dir / "pending_notifications"
|
notification_dir = vmail_dir / "pending_notifications"
|
||||||
if not notification_dir.exists():
|
notification_dir.mkdir(exist_ok=True)
|
||||||
notification_dir.mkdir()
|
|
||||||
metadata = Metadata(vmail_dir)
|
metadata = Metadata(vmail_dir)
|
||||||
notifier = Notifier(notification_dir)
|
notifier = Notifier(notification_dir)
|
||||||
notifier.start_notification_threads(metadata.remove_token_from_addr)
|
notifier.start_notification_threads(metadata.remove_token_from_addr)
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
"""
|
"""
|
||||||
This modules provides notification machinery for transmitting device tokens to
|
This modules provides notification machinery for transmitting device tokens to
|
||||||
a central notification server which in turns contacts a phone provider's notification server
|
a central notification server which in turn contacts a phone provider's notification server
|
||||||
to trigger Delta Chat apps to retrieve messages and provide instant notifications to users.
|
to trigger Delta Chat apps to retrieve messages and provide instant notifications to users.
|
||||||
|
|
||||||
The Notifier class arranges the queuing of tokens in separate PriorityQueues
|
The Notifier class arranges the queuing of tokens in separate PriorityQueues
|
||||||
from which NotifyThreads take and transmit them via HTTPS
|
from which NotifyThreads take and transmit them via HTTPS
|
||||||
to the `notifications.delta.chat` service
|
to the `notifications.delta.chat` service.
|
||||||
which in turn contacts a phone's providers's notification service
|
The current lack of proper HTTP/2-support in Python leads us
|
||||||
which in turn wakes up the Delta Chat app on user devices.
|
to use multiple threads and connections to the Rust-implemented `notifications.delta.chat`
|
||||||
The lack of proper HTTP2-support in Python lets us
|
which itself uses HTTP/2 and thus only a single connection to phone-notification providers.
|
||||||
use multiple threads and connections to the Rust-implemented `notifications.delta.chat`
|
|
||||||
which however uses HTTP2 and thus only a single connection to phone-notification providers.
|
|
||||||
|
|
||||||
If a token fails to cause a successful notification
|
If a token fails to cause a successful notification
|
||||||
it is moved to a retry-number specific PriorityQueue
|
it is moved to a retry-number specific PriorityQueue
|
||||||
@@ -87,7 +85,7 @@ class Notifier:
|
|||||||
|
|
||||||
when = time.time()
|
when = time.time()
|
||||||
if retry_num > 0:
|
if retry_num > 0:
|
||||||
# backup exponentially with number of retries
|
# back off exponentially with number of retries
|
||||||
when += pow(self.NOTIFICATION_RETRY_DELAY, retry_num)
|
when += pow(self.NOTIFICATION_RETRY_DELAY, retry_num)
|
||||||
self.retry_queues[retry_num].put((when, queue_item))
|
self.retry_queues[retry_num].put((when, queue_item))
|
||||||
|
|
||||||
@@ -96,7 +94,7 @@ class Notifier:
|
|||||||
threads = {}
|
threads = {}
|
||||||
for retry_num in range(len(self.retry_queues)):
|
for retry_num in range(len(self.retry_queues)):
|
||||||
# use 4 threads for first-try tokens and less for subsequent tries
|
# use 4 threads for first-try tokens and less for subsequent tries
|
||||||
num_threads = {0: 4}.get(retry_num, 2)
|
num_threads = 4 if retry_num == 0 else 2
|
||||||
threads[retry_num] = []
|
threads[retry_num] = []
|
||||||
for _ in range(num_threads):
|
for _ in range(num_threads):
|
||||||
thread = NotifyThread(self, retry_num, remove_token_from_addr)
|
thread = NotifyThread(self, retry_num, remove_token_from_addr)
|
||||||
|
|||||||
Reference in New Issue
Block a user