From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id 7C8337E587; Sun, 8 Jan 2023 06:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673158570; bh=lQf/Vg8MnfwfJJWZyyccbS1kjRiPQXIbCbha1d9vbVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXBN4HCGndVtRDfgtOi7qWVbLfxFv/Nybk4raGtY0cUXcAQoijzSeS8qtpavipeYM ovaVD5c3ECYxESyDv5V1286TVgU52Qs2NzyPdr+hXbNMWM1Gx7wutW5QraaOZb+iB4 hwpvhuPcV1wtLhlazv+rkU+F4WzInnvmv8J1Xn7dj0W3v6T5wU+bXH7Fg+hBvobxCs sx+38VqNNYlhRaLUmZthKATpApVl7rf3/PAoD+VVTPNwbCE+LabBNqyD/v7tKuvOOI QiCgJw7KM4jQynffOaRmo94Jjdy9YA5gPsEeNuT3Kk+tmwtyVxetyUGHbAb6rnoGcM FNNmaqlANRMtQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 04/11] telegram: Refactor report_err() and move to the DaemonClient() class Date: Sun, 8 Jan 2023 13:15:36 +0700 Message-Id: <20230108061543.1780-5-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230108061543.1780-1-kiizuha@gnuweeb.org> References: <20230108061543.1780-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Instead of adding the report_err() function in the Bot() class, move it to the DaemonClient() class. Also, change the report_err() function as follows: def report_err(self, e: DaemonException): # code for reporting error goes here Signed-off-by: Muhammad Rizki --- daemon/telegram/mailer/listener.py | 8 +------- daemon/telegram/packages/client.py | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 6482a66..5ac618f 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -68,12 +68,6 @@ class Bot(): self.db.ping(reconnect=True, attempts=reconnect_attempts, delay=delay_in_secs) - async def report_err(caption): - if not caption: - caption = "No lore URL" - exc_str = utils.catch_err() - self.logger.warning(exc_str) - await self.client.send_log_file(caption) async def __run(self): self.logger.info("Running...") @@ -84,7 +78,7 @@ class Bot(): except (OperationalError, DatabaseError) as e: await self.handle_db_error(e) except: - await self.report_err(url) + await self.client.report_err(url) if not self.isRunnerFixed: self.isRunnerFixed = True diff --git a/daemon/telegram/packages/client.py b/daemon/telegram/packages/client.py index 58195b9..c5b0b33 100644 --- a/daemon/telegram/packages/client.py +++ b/daemon/telegram/packages/client.py @@ -14,6 +14,7 @@ from logger import BotLogger from telegram import config from telegram.database import DB from .decorator import handle_flood +from exceptions import DaemonException class DaemonClient(Client): @@ -27,6 +28,13 @@ class DaemonClient(Client): self.logger = logger + async def report_err(self, e: DaemonException): + capt = f"Atom URL: {e.atom_url}\n" + capt += f"Thread URL: {e.thread_url}" + self.logger.warning(e.original_exception) + await self.send_log_file(capt) + + @handle_flood async def send_log_file(self, caption: str): filename = self.logger.handlers[0].baseFilename -- Muhammad Rizki