remove lock

This commit is contained in:
emmatveev 2024-04-30 11:28:13 +03:00
parent 7dc6df0182
commit 0f16bff9ac
2 changed files with 14 additions and 21 deletions

30
bot.py
View File

@ -42,14 +42,13 @@ class Core:
self.set_state('pause')
if self.state == 'dialog':
current_dialog = mongo.get_current_dialog(self.chat_id)
with redis.lock('search'):
mongo.finish_dialog(current_dialog['_id'])
if self.chat_id == current_dialog['chat_id_1']:
another_chat_id = current_dialog['chat_id_2']
else:
another_chat_id = current_dialog['chat_id_1']
self.send_message('🤖 Диалог окончен, жду тебя снова!')
self.start_new_dialog([another_chat_id])
mongo.finish_dialog(current_dialog['_id'])
if self.chat_id == current_dialog['chat_id_1']:
another_chat_id = current_dialog['chat_id_2']
else:
another_chat_id = current_dialog['chat_id_1']
self.send_message('🤖 Диалог окончен, жду тебя снова!')
self.start_new_dialog([another_chat_id])
return
if self.state == 'pause':
self.send_message('🤖 Сейчас твой аккаунт не активен. Активируй его с помощью команды /start')
@ -58,14 +57,13 @@ class Core:
self.send_message('🤖 Поиск собеседника окончен, жду тебя снова!')
return
if self.message_text == '/next' or self.message_text == '/start':
with redis.lock('search'):
if self.state == 'dialog':
dialog = mongo.get_current_dialog(self.chat_id)
self.start_new_dialog([dialog['chat_id_1'], dialog['chat_id_2']])
return
else:
self.start_new_dialog([self.chat_id])
return
if self.state == 'dialog':
dialog = mongo.get_current_dialog(self.chat_id)
self.start_new_dialog([dialog['chat_id_1'], dialog['chat_id_2']])
return
else:
self.start_new_dialog([self.chat_id])
return
def handle_state_search(self):
self.send_message('🤖 Поиски собеседника продолжаются')

View File

@ -23,11 +23,6 @@ class RedisClient:
with self.cli as cli:
cli.set(f"ruletka_{key}", value)
@contextlib.contextmanager
def lock(self, key):
with self.cli.lock(f"ruletka_{key}"):
yield
redis_client = RedisClient(
settings.REDIS_HOST,