From 169a1ef774f1227101035769929d9262310959c4 Mon Sep 17 00:00:00 2001 From: rking32 Date: Fri, 4 Jun 2021 19:15:06 +0530 Subject: [PATCH] removed force checking for previous instance --- config.env.sample | 6 +++++- init/init.sh | 1 - init/utils.sh | 1 + userge/config.py | 1 + userge/core/client.py | 24 +++++++++++------------- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/config.env.sample b/config.env.sample index 487f0466a..88837479e 100644 --- a/config.env.sample +++ b/config.env.sample @@ -42,6 +42,10 @@ LOG_CHANNEL_ID="" LOAD_UNOFFICIAL_PLUGINS=false +# assert running single Userge instance to prevent from AUTH_KEY_DUPLICATED error. +ASSERT_SINGLE_INSTANCE=false + + # This is best if you wanna add your own plugins # Set this to fork of https://github.com/UsergeTeam/Custom-Plugins and add your plugins CUSTOM_PLUGINS_REPO="" @@ -52,7 +56,7 @@ WORKERS="" # Telegram Chat id For Updates of Rss Feed -RSS_CHAT_ID = "" +RSS_CHAT_ID="" # Googel Drive API Keys from https://console.developers.google.com/ diff --git a/init/init.sh b/init/init.sh index 69a80d654..bc0e85913 100644 --- a/init/init.sh +++ b/init/init.sh @@ -35,7 +35,6 @@ initUserge() { startUserge() { startLogBotPolling runPythonModule userge "$@" - waitProc } stopUserge() { diff --git a/init/utils.sh b/init/utils.sh index c9403dbe5..54da571f0 100644 --- a/init/utils.sh +++ b/init/utils.sh @@ -47,6 +47,7 @@ runPythonCode() { runPythonModule() { python${pVer%.*} -m "$@" & setProc $! + waitProc } gitInit() { diff --git a/userge/config.py b/userge/config.py index 41a045fa2..e1a791eb2 100644 --- a/userge/config.py +++ b/userge/config.py @@ -66,6 +66,7 @@ class Config: HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME") G_DRIVE_IS_TD = os.environ.get("G_DRIVE_IS_TD") == "true" LOAD_UNOFFICIAL_PLUGINS = os.environ.get("LOAD_UNOFFICIAL_PLUGINS") == "true" + ASSERT_SINGLE_INSTANCE = os.environ.get("ASSERT_SINGLE_INSTANCE", "false").lower() == "true" THUMB_PATH = DOWN_PATH + "thumb_image.jpg" TMP_PATH = "userge/plugins/temp/" MAX_MESSAGE_LENGTH = 4096 diff --git a/userge/core/client.py b/userge/core/client.py index 072c9a524..eaf3ab081 100644 --- a/userge/core/client.py +++ b/userge/core/client.py @@ -48,9 +48,10 @@ async def _set_running(is_running: bool) -> None: async def _is_running() -> bool: - data = await _USERGE_STATUS.find_one({'_id': 'USERGE_STATUS'}) - if data: - return bool(data['is_running']) + if Config.ASSERT_SINGLE_INSTANCE: + data = await _USERGE_STATUS.find_one({'_id': 'USERGE_STATUS'}) + if data: + return bool(data['is_running']) return False @@ -188,18 +189,15 @@ async def start(self) -> None: timeout = 30 # 30 sec max_ = 1800 # 30 min - while True: - if await _is_running(): - _LOG.info(_LOG_STR, "Waiting for the Termination of " - f"previous Userge instance ... [{timeout} sec]") - time.sleep(timeout) - - counter += timeout - if counter < max_: - continue + while await _is_running(): + _LOG.info(_LOG_STR, "Waiting for the Termination of " + f"previous Userge instance ... [{timeout} sec]") + time.sleep(timeout) + counter += timeout + if counter >= max_: _LOG.info(_LOG_STR, f"Max timeout reached ! [{max_} sec]") - break + break _LOG.info(_LOG_STR, "Starting Userge") await _set_running(True)