-
Notifications
You must be signed in to change notification settings - Fork 290
feat: [redis] add optional redis PEL reading support #2568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: [redis] add optional redis PEL reading support #2568
Conversation
|
@Lancetnik I was wondering if you might have an opinion on this implementation for reading of pending redis messages |
|
@JonathanSerafini sorry, I am nor sure, that I got your second idea correctly. Can you explain more detail, please? Probably, with pseudocode. But, I like your approach |
|
@Lancetnik Sure ... subscriber = broker.subscriber(stream=queue)
@subscriber
async def handler(msg): ...
async def pending_monitor(subscriber: StreamSubscriber, interval: float, idle: int) -> None:
while True:
# optionally get first xpending message
# optionally filter xpending by idle
# or optionally walk the list of xpending_range and delete those where delivery_attempts too high
if has_pending:
subscriber.read_pending = True
else:
subscriber.read_pending = False
await asyncio.sleep(interval)
subscriber.add_task(pending_monitor, subscriber, 15, 30 * 1000)above is pseudo-code ... it doesn't quite work with the declarative approach out of the box would be cleaner if it was either builtin support or subscribers had some sort of support for registering tasks as part of the decorator. |
Not "tasks" exactly, but we made smth close here - https://faststream.ag2.ai/latest/howto/nats/in-progress/ |
e320405 to
d47d4ff
Compare
8177181 to
2513f7d
Compare
By the looks of it, it does seem like a background task would be warranted given that it's more "subscriber lifecycle" than it is "message lifecycle" as it is for NATs. |
Description
This change adds an initial implementation for an optional reading mode for the redis stream
subscriber whereby it will attempt to read messages from the PEL first and then continue on
reading new messages on the stream.
At present this mode is an optional and disable so as to not alter the existing behaviour.
On it's own, this change doesn't "do" much. However, by utilizing the
resume_frommethodit now becomes possible to periodically have the consumer switch from reading new messages
to reading from the PEL.
In a subsequent PR, i could add the resumable option to the subscriber settings and potentially
also add a background task to monitor the pending list to set resume_from to consume pending.
Type of change
Please delete options that are not relevant.
Checklist
just lintshows no errors)just test-coveragejust static-analysis