-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
George Burton
committed
Apr 13, 2024
1 parent
bfcfd65
commit 8896f46
Showing
4 changed files
with
31 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from faststream.redis import RedisBroker | ||
|
||
from redbox.models import File | ||
|
||
|
||
class FilePublisher: | ||
"""This class is a bit of a hack to overcome a shortcoming (bug?) in faststream | ||
whereby the broker is not automatically connected in sub-applications. | ||
TODO: fix this properly, or raise an issue against faststream | ||
""" | ||
|
||
def __init__(self, broker: RedisBroker, queue_name: str): | ||
self.connected = False | ||
self.broker = broker | ||
self.queue_name = queue_name | ||
|
||
async def publish(self, file: File): | ||
if not self.connected: | ||
# we only do this once | ||
await self.broker.connect() | ||
self.connected = True | ||
return self.broker.publish(file, self.queue_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters