Skip to content

wrote 2 implementations for a load balancer#28

Open
IvanGrigoriev11 wants to merge 5 commits intomainfrom
u/ivan/load_balancer
Open

wrote 2 implementations for a load balancer#28
IvanGrigoriev11 wants to merge 5 commits intomainfrom
u/ivan/load_balancer

Conversation

@IvanGrigoriev11
Copy link
Copy Markdown
Owner

No description provided.

@IvanGrigoriev11 IvanGrigoriev11 requested review from a-and-v and removed request for a-and-v July 18, 2023 19:54
@IvanGrigoriev11 IvanGrigoriev11 requested a review from a-and-v July 18, 2023 21:49
Comment thread src/load_balancer.py


class LockService(Protocol):
"""Load balancer interface based on Redis."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an interface. What does Redis has to do with the interface?

Comment thread src/load_balancer.py
@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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a DB in the context of an interface? Speak in terms of the behavior, not particular implementation.

Comment thread src/load_balancer.py
def __init__(self):
# TO DO: do not forget to write to right address

self._pool = aioredis.ConnectionPool.from_url(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be passed from the outside, not created here. It's a dependency.

Comment thread src/load_balancer.py

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock time should be passed as a parameter of lock acquisition or at lest be passed in the constructor.

Comment thread src/load_balancer.py
return False


class NoOp(LockService):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NoOp means not operational. Meaning it's a dummy implementation. Why is it using Redis?

Comment thread src/main.py
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):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean? If lock exists owned by who?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants