Skip to content

Commit

Permalink
removed force checking for previous instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Jun 4, 2021
1 parent 3b7b62c commit 169a1ef
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
6 changes: 5 additions & 1 deletion config.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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/
Expand Down
1 change: 0 additions & 1 deletion init/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ initUserge() {
startUserge() {
startLogBotPolling
runPythonModule userge "$@"
waitProc
}

stopUserge() {
Expand Down
1 change: 1 addition & 0 deletions init/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ runPythonCode() {
runPythonModule() {
python${pVer%.*} -m "$@" &
setProc $!
waitProc
}

gitInit() {
Expand Down
1 change: 1 addition & 0 deletions userge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions userge/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 169a1ef

Please sign in to comment.