Skip to content

Commit

Permalink
remove comm
Browse files Browse the repository at this point in the history
(cherry picked from commit 8c76d3d)
  • Loading branch information
Belissimo-T committed Nov 8, 2024
1 parent ec267cd commit 2c2f7f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 205 deletions.
6 changes: 0 additions & 6 deletions backend/plan_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import xml.etree.ElementTree as ET

from shared import comm
from . import schools, default_plan, events
from shared.cache import Cache
from .meta_extractor import MetaExtractor
Expand Down Expand Up @@ -169,11 +168,6 @@ def compute_plan_revision(self, date: datetime.date, timestamp: datetime.datetim
revision=timestamp,
has_vplan=vplan_kl is not None
))
comm.send_message(comm.NewRevisionAvailable(
school_number=self.school_number,
date=date,
revision=timestamp
))

_t1 = events.now()
try:
Expand Down
47 changes: 22 additions & 25 deletions endpoints/webpush.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import json
import os

from shared import comm
from shared import mongodb

import pywebpush
Expand Down Expand Up @@ -29,29 +29,26 @@ def send_message(subscription: dict, data: dict):
)


def msg_handler(msg: comm.Message) -> comm.Message | None:
if isinstance(msg, comm.NewRevisionAvailable):
if not mongodb.ENABLED:
return None
res = _USERS_COLLECTION.find({
"authorized_schools": msg.school_number,
"webpush_subscriptions": {"$exists": True}
})
for user in res:
for subscription in user.get("webpush_subscriptions", []):
data = {
"type": "new-revision-available",
"data": msg.serialize()
def handle_new_revision(school_number: str, date: datetime.date, revision: datetime.datetime):
if not mongodb.ENABLED:
return None
res = _USERS_COLLECTION.find({
"authorized_schools": school_number,
"webpush_subscriptions": {"$exists": True}
})
for user in res:
for subscription in user.get("webpush_subscriptions", []):
data = {
"type": "new-revision-available",
"data": {
"school_number": school_number,
"date": date.isoformat(),
"revision": revision.isoformat()
}
}

try:
send_message(subscription, data)
except pywebpush.WebPushException as e:
print(e.response.text)
return None

return None


def start_listen():
comm.listen_messages(msg_handler)
try:
send_message(subscription, data)
except pywebpush.WebPushException as e:
print(e.response.text)
return None
174 changes: 0 additions & 174 deletions shared/comm.py

This file was deleted.

0 comments on commit 2c2f7f3

Please sign in to comment.