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 3DDB97E375; Sun, 8 Jan 2023 08:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673165296; bh=lIw/cWoC4FkjbAB/Y2ux36LqtDJKvRN4802P6EOSs7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MB/+L1jQIN22pJCm25Tddh9nNgRj35MR66CiYvx3cjP3QnwqWtBSOhwSWKjTz3yWV pDKSziJuScohUfRlA7uM/gvNL7GhRbs7Ji3V2686w7+bE1gHriU7sOuj+iA0hXyGm7 g3BMYW6jqrkzguZM0gR7z1bjYYMkhm2vHItDMj2SjmMdCTXilXa3z7FdYj8ATYQfF/ klon+0n41OJ5g0Zsrt3C8ISCLiElw1W3hnAwP5Gre8t/nAWkw6ijCa258HxK/MD7do fBr09+N9RAeMTnnCTO4nCswxMoxfMEQBfEfCKXry/FAs9ZmgHYTVZT5EDo2DB4TGhV cjOpDaUAMOuDQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 08/11] discord: Implement the report_err() and DaemonException() error class Date: Sun, 8 Jan 2023 15:07:38 +0700 Message-Id: <20230108080741.1914-9-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: After adding a report_err() function within the GWClient() class, implement it in dscord/mailer/listener.py to report error logs to the Discord channel. Additionally, also implement the DaemonException() function to handle errors. Signed-off-by: Muhammad Rizki --- daemon/dscord/mailer/listener.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/daemon/dscord/mailer/listener.py b/daemon/dscord/mailer/listener.py index a225f46..aa44603 100644 --- a/daemon/dscord/mailer/listener.py +++ b/daemon/dscord/mailer/listener.py @@ -14,6 +14,7 @@ from dscord.gnuweeb import GWClient from atom.scraper import Scraper from atom import utils from enums import Platform +from exceptions import DaemonException class Mutexes: @@ -51,8 +52,19 @@ class Listener: async def __run(self): self.logger.info("Running...") - for url in self.db.get_atom_urls(): - await self.__handle_atom_url(url) + url = None + + try: + for url in self.db.get_atom_urls(): + await self.__handle_atom_url(url) + except DaemonException as e: + e.set_atom_url(url) + await self.client.report_err(e) + except: + e = DaemonException() + e.set_atom_url(url) + e.set_message(utils.catch_err()) + await self.client.report_err(e) if not self.isRunnerFixed: self.isRunnerFixed = True @@ -72,9 +84,10 @@ class Listener: mail = await self.scraper.get_email_from_url(url) await self.__handle_mail(url, mail) except: - exc_str = utils.catch_err() - self.client.logger.warning(exc_str) - await self.client.send_log_file(url) + e = DaemonException() + e.set_thread_url(url) + e.set_message(utils.catch_err()) + raise e async def __handle_mail(self, url, mail): -- Muhammad Rizki