Skip to content

Commit

Permalink
Add Publisher/Subscriber classes for cache topic
Browse files Browse the repository at this point in the history
  • Loading branch information
octonawish-akcodes authored and spbnick committed Aug 9, 2023
1 parent 5415713 commit f75ede3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions kcidb/mq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,43 @@ def decode_data(self, message_data):
return pattern_set


class URLListPublisher(Publisher):
"""URL list queue publisher"""

def encode_data(self, data):
"""
Encode a list of URLs into message data.
Args:
data: The list of URLs to encode.
Returns:
The encoded message data.
Raises:
An exception in case data encoding failed.
"""
assert isinstance(data, list)
assert all(isinstance(url, str) for url in data)
return "\n".join(data).encode()


class URLListSubscriber(Subscriber):
"""URL list queue subscriber"""

def decode_data(self, message_data):
"""
Decode message data to extract a list of URLs.
Args:
message_data: The message data from the message queue
Returns:
The decoded list of URLs.
Raises:
An exception in case data decoding failed.
"""
return message_data.decode().splitlines()


class EmailPublisher(Publisher):
"""Email queue publisher"""

Expand Down

0 comments on commit f75ede3

Please sign in to comment.