-
Notifications
You must be signed in to change notification settings - Fork 64
Coordination lock api #723
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?
Conversation
… - refactor - thin async client -> all session logic to lock object
…e only for lock logic (release and so on) , stream about session work -> making stream_stream canal and so on, reconnector -> make this stream stable
| self._req_id = None | ||
|
|
||
| async def acquire(self): | ||
| return await self.__aenter__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
должно быть наоборот, в enter мы должны вызывать acquire, а в exit - release.
| async def release(self): | ||
| await self.__aexit__(None, None, None) | ||
|
|
||
| async def create(self, init_limit, init_data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне кажется все методы, кроме acquire и release (ну и возможно close) должны быть непубличными, то есть с приставкой _ перед названием метода. Подумай, при каких сценариях вообще пользователю нужно будет вызывать условный create или delete?
|
|
||
| self._stream = self._reconnector.get_stream() | ||
|
|
||
| async def _wait_for_response(self, req_id: int, *, kind: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этот метод выглядит странным. по наличию while True он похож на какой-то бекграунд луп, однако вызываем мы его на каждый вызов
сейчас возможна ситуация, где мы в параллель запустим два запроса и получим в каждом из них противоречивые ответы
у тебя есть req_id, по нему ты можешь однозначно определить нужный тебе респонз, нам не нужно для этого каждый раз инициировать опрос сервера, можно делать это в фоне и синкаться по req_id
| self, | ||
| client, | ||
| name: str, | ||
| node_path: Optional[str] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему тут есть какой-то дефолтно пустой node_path?
| lock = client.lock("test_lock", node_path) | ||
|
|
||
| create_resp: CreateSemaphoreResult = await lock.create(init_limit=1, init_data=b"init-data") | ||
| assert create_resp.status == StatusCode.SUCCESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем это пользователю? в случае ошибки мы получим эксепшн, в случае успеха - нет
| lock2_acquired.set() | ||
| await asyncio.sleep(0.5) | ||
|
|
||
| async with client.lock("test_lock", node_path) as lock1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
очень сложно это все читать. давай будем пользоваться методами acquire и release, а также не будем делать этот километровый дескрайб
No description provided.