Skip to content

Commit

Permalink
reading-list-updater: Publish update requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenson committed Oct 1, 2024
1 parent 9f66089 commit 56ed0d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions services/reading-list-updater/hive/reading_list_updater/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ def from_email_message(cls, email: EmailMessage) -> ReadingListEntry:
kwargs["timestamp"] = date.datetime

return cls(link, title, notes, **kwargs)

def as_dict(self) -> dict[str]:
report = {
"meta": {
"timestamp": str(self.timestamp),
"type": "reading_list_entry",
},
"link": self.link,
}
if self.title:
report["title"] = self.title
if self.notes:
report["notes"] = self.notes
return report
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@dataclass
class Service:
email_queue: str = "readinglist.emails.received"
updates_queue: str = "readinglist.update.requests"
on_channel_open: Optional[Callable[[Channel], None]] = None

def on_email_received(
Expand All @@ -30,7 +31,10 @@ def on_email_received(
if content_type != "message/rfc822":
raise ValueError(content_type)
entry = ReadingListEntry.from_email_bytes(body)
raise NotImplementedError(entry)
channel.publish_request(
message=entry.as_dict(),
routing_key=self.updates_queue,
)

def run(self):
with blocking_connection(on_channel_open=self.on_channel_open) as conn:
Expand Down

0 comments on commit 56ed0d0

Please sign in to comment.