Skip to content

Commit

Permalink
Add new email_notification_dispatcher thread in server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
IonesioJunior committed Sep 16, 2024
1 parent 43e9a2e commit 4808ef1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/syft/src/syft/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path
import subprocess # nosec
import sys
import threading
from time import sleep
import traceback
from typing import Any
Expand Down Expand Up @@ -455,6 +456,29 @@ def __init__(
self.run_peer_health_checks(context=context)

ServerRegistry.set_server_for(self.id, self)
email_dispatcher = threading.Thread(target=self.email_notification_dispatcher)
email_dispatcher.daemon = True
email_dispatcher.start()

def email_notification_dispatcher(self) -> None:
while True:
context = AuthedServiceContext(
server=self,
credentials=self.verify_key,
role=ServiceRole.ADMIN,
)

notifier_settings = self.services.notifier.settings(
context=context
).unwrap()

for email_template, email_queue in notifier_settings.email_queue.items():
email_frequency = notifier_settings.email_frequency[email_template]
notifier_settings.send_batched_notification(
context, email_queue, email_frequency
)
# print(f"Email Frequency: {notifier_settings.email_queue}")
sleep(5)

def set_log_level(self, log_level: int | str | None) -> None:
def determine_log_level(
Expand Down

0 comments on commit 4808ef1

Please sign in to comment.