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 258D77E5A4; Sun, 8 Jan 2023 08:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673165288; bh=lQf/Vg8MnfwfJJWZyyccbS1kjRiPQXIbCbha1d9vbVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SbzNFsExDUtrm4BDw+1POMLcgfoYKkAANGJMQZpiMRpDrQ9AXSRBWIPKa2ZAYTuAT ouhEL1DEit00wuzf/n92Z5uIlDNo75/Db323LVgtAOHs8MklcxtsBuCE45hottW2Ov +rSR/Dawbl2q8/kCHri07Kyc4yzk+kItyl4cOKXYEyGyakvSOgYCwswUrbgk036T8E PSpO2FZV8MLpLjY1+ECJMql0V3IYvvSPBMiFD0HHtxraKYi77uvA1Y3oqeMWUmhnV/ VQ3WH286Anpnc1C5m5uPXJJkrAop3MWoB/v+5viGQubXWWZf0wWqp8SwT8zNDaTWKJ JoYeWto5TtuEg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 04/11] telegram: Refactor report_err() and move to the DaemonClient() class Date: Sun, 8 Jan 2023 15:07:34 +0700 Message-Id: <20230108080741.1914-5-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230108080741.1914-1-kiizuha@gnuweeb.org> References: <20230108080741.1914-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