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,URIBL_BLOCKED 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 E81147E3B8; Tue, 3 Jan 2023 06:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672727825; bh=NiECnaAI/PaItX+2Ct3Cg8orvLQKH+GWtSlMFAgFYg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOKeHSbNNDEztPEfDD2DWoLvGGoCmseatWRju8t08SLOmyJdSFNJkP9W2CRpMLlyu YxHBa4uoE3BtVljuTgpzJ28H8BmPjtQydpLpFSXUDc6It6MG9FQLQkJmmEF1PJB5SI IqQIgqpLyGAfCNHJyCO2jWb0LLC9zpQASZ49Zfq+QdMv3vDjUqhkL+gxdGRSHHgm7F b6ZAb8+GWQo7dNW7e0Hce8KQ5NTdI8Xoa5BFiDlw8/SCDGdFzwzcqNdUhOzdp1NlPj j7aO1044U8wzIu82WoGvPy4IZbjvccvU0JavwTHdFiDgglm3riEn1CrphkzpIuNUQ0 qnMFKcm8oyDog== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 02/13] refactor(telegram): Move report_err() to the DaemonClient() class Date: Tue, 3 Jan 2023 13:36:30 +0700 Message-Id: <20230103063641.1680-3-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230103063641.1680-1-kiizuha@gnuweeb.org> References: <20230103063641.1680-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. 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 044de6a..8425dd4 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -61,12 +61,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...") @@ -77,7 +71,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..f543caa 100644 --- a/daemon/telegram/packages/client.py +++ b/daemon/telegram/packages/client.py @@ -27,6 +27,14 @@ class DaemonClient(Client): self.logger = logger + async def report_err(self, caption): + if not caption: + caption = "No lore URL" + exc_str = utils.catch_err() + self.logger.warning(exc_str) + await self.send_log_file(caption) + + @handle_flood async def send_log_file(self, caption: str): filename = self.logger.handlers[0].baseFilename -- Muhammad Rizki