python-telegram-bot / python-telegram-bot

We have made you a wrapper you can't refuse
https://python-telegram-bot.org
GNU General Public License v3.0
26.27k stars 5.34k forks source link

[QUESTION] How to work with persistent conversation data across multiple processes #4452

Closed HK-Mattew closed 2 months ago

HK-Mattew commented 2 months ago

Issue I am facing

Hello,

I am facing difficulty in keeping conversations active between multiple processes for the same bot. I created a data persistence based on the BasePersistence class.,

And it works well for most of the methods, such as: get_...data(...), update...data(...) and refresh...data(...). This works well because it has the refresh..._data(...) method that is called always before a handler is executed and then the data in memory is synchronized with the data in the Data Store (Database).

And the limitation I faced was that there is no refresh_conversation_data(...) method to synchronize the local data in memory with the database and so it is not possible to keep the data synchronized between more than one process.

I run my bot in webhook mode, and there the webhook requests are distributed among processes for the same bot. (Hence the need for multiple processes).

Is there any reason not to have the refresh_conversation_data(...) method?

Traceback to the issue

No response

Related part of your code

No response

Operating System

Ubuntu 22.04.4 LTS

Version of Python, python-telegram-bot & dependencies

Bot API 6.6
Python 3.10.13 (main, Sep  5 2023, 06:03:44) [GCC 11.4.0]
Bibo-Joshi commented 2 months ago

Hi. There is no specific reason not to have refresh_conversation_data. AFAIK ConversationHandler are just rarely used in load balancing/serverless setups, at least I have only seen a hand full of questions about this. I've added your point to #2770. I'm aware that this only of little benefit for you as #2770 has been on our list since ages, but at the current point I don't see us adding significant new functionality to CH …

HK-Mattew commented 2 months ago

Olá. Não há nenhuma razão específica para não ter refresh_conversation_data. AFAIK ConversationHandlersão raramente usados ​​​​em balanceamento de carga/configurações sem servidor, pelo menos eu só vi uma pergunta sobre isso. Adicionei seu ponto ao #2770 . Estou ciente de que isso só traz pouco benefício para você, pois o #2770 está em nossa lista há séculos, mas no momento atual não vejo que estamos adicionando novas funcionalidades específicas ao CH …

Got it, I'll follow the discussion. Thanks.