wrote 2 implementations for a load balancer#28
Open
IvanGrigoriev11 wants to merge 5 commits intomainfrom
Open
Conversation
a-and-v
reviewed
Jul 18, 2023
|
|
||
|
|
||
| class LockService(Protocol): | ||
| """Load balancer interface based on Redis.""" |
Collaborator
There was a problem hiding this comment.
it's an interface. What does Redis has to do with the interface?
a-and-v
reviewed
Jul 18, 2023
| @abstractmethod | ||
| async def acquire_lock(self, chat_id: int) -> None: | ||
| """Set the lock on operations with a specific chat. | ||
| If the key 'chat_id' exists in the DB, the lock is acquired on the chat. |
Collaborator
There was a problem hiding this comment.
What is a DB in the context of an interface? Speak in terms of the behavior, not particular implementation.
a-and-v
reviewed
Jul 18, 2023
| def __init__(self): | ||
| # TO DO: do not forget to write to right address | ||
|
|
||
| self._pool = aioredis.ConnectionPool.from_url( |
Collaborator
There was a problem hiding this comment.
That should be passed from the outside, not created here. It's a dependency.
a-and-v
reviewed
Jul 18, 2023
|
|
||
| async with aioredis.Redis(connection_pool=self._pool) as conn: | ||
| # TO DO: discuss which expiration time is more preferable for holding the key and add it | ||
| await conn.execute_command("SET", chat_id, 1, "NX", "EX", 5) |
Collaborator
There was a problem hiding this comment.
lock time should be passed as a parameter of lock acquisition or at lest be passed in the constructor.
a-and-v
reviewed
Jul 18, 2023
| return False | ||
|
|
||
|
|
||
| class NoOp(LockService): |
Collaborator
There was a problem hiding this comment.
NoOp means not operational. Meaning it's a dummy implementation. Why is it using Redis?
a-and-v
reviewed
Jul 18, 2023
| if chat_handler_snapshot is None: | ||
| chat_handler = await ChatHandler.create( | ||
| await self.state_factory.make_greeting_state(), chat_id | ||
| if not lock.check_existing_lock(chat_id): |
Collaborator
There was a problem hiding this comment.
What does it mean? If lock exists owned by who?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.