From ab34a189bb74ca3c146fb6f7c2a18bc41f33a899 Mon Sep 17 00:00:00 2001 From: rking32 Date: Sat, 16 Jan 2021 17:27:20 +0530 Subject: [PATCH] some optimizations --- init/checks.sh | 6 ++++++ init/init.sh | 5 ++--- userge/config.py | 2 +- userge/plugins/misc/gdrive.py | 5 ++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/init/checks.sh b/init/checks.sh index 776b4c81f..95500c125 100644 --- a/init/checks.sh +++ b/init/checks.sh @@ -64,6 +64,12 @@ _checkDefaultVars() { test -z ${!key} && eval $key=${def_vals[$key]} set +a done + if test $WORKERS -le 0; then + WORKERS=$(($(nproc)+4)) + elif test $WORKERS -gt 32; then + WORKERS=32 + fi + export MOTOR_MAX_WORKERS=$WORKERS DOWN_PATH=${DOWN_PATH%/}/ if [[ -n $HEROKU_API_KEY && -n $HEROKU_APP_NAME ]]; then local herokuErr=$(runPythonCode ' diff --git a/init/init.sh b/init/init.sh index f2789e7df..1a831f4cf 100644 --- a/init/init.sh +++ b/init/init.sh @@ -25,31 +25,30 @@ initUserge() { } startUserge() { + startLogBotPolling runPythonModule userge "$@" } stopUserge() { sendMessage "Exiting Userge ..." + endLogBotPolling exit 0 } handleSigTerm() { log "Exiting With SIGTERM (143) ..." stopUserge - endLogBotPolling exit 143 } handleSigInt() { log "Exiting With SIGINT (130) ..." stopUserge - endLogBotPolling exit 130 } runUserge() { initUserge - startLogBotPolling startUserge "$@" stopUserge } diff --git a/userge/config.py b/userge/config.py index c49c09f8d..c86511da1 100644 --- a/userge/config.py +++ b/userge/config.py @@ -29,7 +29,7 @@ class Config: """ Configs to setup Userge """ API_ID = int(os.environ.get("API_ID")) API_HASH = os.environ.get("API_HASH") - WORKERS = min(32, int(os.environ.get("WORKERS")) or os.cpu_count() + 4) + WORKERS = int(os.environ.get("WORKERS")) or os.cpu_count() + 4 BOT_TOKEN = os.environ.get("BOT_TOKEN", None) HU_STRING_SESSION = os.environ.get("HU_STRING_SESSION", None) OWNER_ID = tuple(filter(lambda x: x, map(int, os.environ.get("OWNER_ID", "0").split()))) diff --git a/userge/plugins/misc/gdrive.py b/userge/plugins/misc/gdrive.py index 2940c0001..ae57a53fc 100644 --- a/userge/plugins/misc/gdrive.py +++ b/userge/plugins/misc/gdrive.py @@ -958,7 +958,10 @@ async def gsetup_(message: Message): """ setup creds """ link = "https://theuserge.github.io/deployment.html#3-g_drive_client_id--g_drive_client_secret" if Config.G_DRIVE_CLIENT_ID and Config.G_DRIVE_CLIENT_SECRET: - await Worker(message).setup() + if message.chat.id == Config.LOG_CHANNEL_ID: + await Worker(message).setup() + else: + await message.err("try in log channel") else: await message.edit( "`G_DRIVE_CLIENT_ID` and `G_DRIVE_CLIENT_SECRET` not found!\n"