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 E21AA7E416; Tue, 3 Jan 2023 06:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1672727845; bh=fRszFihfH7Hj/30LTmw4UHjpyZ1l1eMXp8TLm7O3szE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qsmEOlvXe831+2ADndktLf6lyjDBy0zLMAcEKjLpwd98HGRYjcitdi1cz7IQPu0Zm 9nmIOmX3Y6w6NLVEJxBF+i6z0QJcRLM5PLF9+Phj1c21dMGRNbDnG6AQ/M6PYnfLox dAgYMHtoQvoNs0/qcfxczAPIhJ1SHPR0K7oGqmmWCtiap8sgkajgTtUIaa81Zy2n9H UjJUalJwDm7SrN5j4DPc0ZLXMYXWY/UI5TLLyxozEUWJspNTRXhy+VUuLG51d4mQ8M Wtjm4ATZ1gi035HMg7jikwSEhULf7R18iFRBDvZJli4eRvogG77LeL+Sf1uEfj9ty3 Lfgbkf0weDq5g== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 11/13] feat(discord): Handle MySQL connection error in the mail listener Date: Tue, 3 Jan 2023 13:36:39 +0700 Message-Id: <20230103063641.1680-12-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: This error handling is to reconnect the MySQL connection when sometimes MySQL service having a problem or has been restarted while the bot is still running. Signed-off-by: Muhammad Rizki --- daemon/dscord/mailer/listener.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/daemon/dscord/mailer/listener.py b/daemon/dscord/mailer/listener.py index ec58f6a..2bde0f0 100644 --- a/daemon/dscord/mailer/listener.py +++ b/daemon/dscord/mailer/listener.py @@ -6,6 +6,7 @@ import asyncio import re +from mysql.connector.errors import OperationalError, DatabaseError from apscheduler.schedulers.asyncio import AsyncIOScheduler from discord import File from discord import Message @@ -74,6 +75,8 @@ class Listener: try: for url in self.db.get_atom_urls(): await self.__handle_atom_url(url) + except (OperationalError, DatabaseError) as e: + await self.handle_db_error(e) except: await self.client.report_err(url) -- Muhammad Rizki