GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: GNU/Weeb Mailing List <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	Muhammad Rizki <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>
Subject: [PATCH v1 1/2] telegram: listener: Fix missing MySQL error recovery function
Date: Sun, 25 Dec 2022 05:00:07 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

From: Ammar Faizi <[email protected]>

When I restarted the MySQL server, the program kept looping in the
report function, reporting the same error:

   "Lost connection to MySQL server during query"

This happened because commit ce17f3e8016c ("telegram: Implement the log
message for catching errors") added an error logging using a 'try and
except' statement. This statement effectively kills the MySQL recovery
function that the caller ('__run' function) provides.

Create a new function wrapper, report_err(). Also, make sure the MySQL
error recovery function is called.

Fixes: ce17f3e8016c ("telegram: Implement the log message for catching errors")
Signed-off-by: Ammar Faizi <[email protected]>
---
 daemon/telegram/mailer/listener.py | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py
index 5a182d0..044de6a 100644
--- a/daemon/telegram/mailer/listener.py
+++ b/daemon/telegram/mailer/listener.py
@@ -61,19 +61,23 @@ 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...")
+		url = None
 		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:
-			exc_str = utils.catch_err()
-			self.logger.warning(exc_str)
-			capt = "Unknown raw lore URL, see full details in the log file."
-			await self.client.send_log_file(capt)
+			await self.report_err(url)
 
 		if not self.isRunnerFixed:
 			self.isRunnerFixed = True
@@ -89,13 +93,8 @@ class Bot():
 	async def __handle_atom_url(self, url):
 		urls = await self.scraper.get_new_threads_urls(url)
 		for url in urls:
-			try:
-				mail = await self.scraper.get_email_from_url(url)
-				await self.__handle_mail(url, mail)
-			except:
-				exc_str = utils.catch_err()
-				self.logger.warning(exc_str)
-				await self.client.send_log_file(url)
+			mail = await self.scraper.get_email_from_url(url)
+			await self.__handle_mail(url, mail)
 
 
 	async def __handle_mail(self, url, mail):
-- 
Ammar Faizi


  reply	other threads:[~2022-12-24 22:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24 22:00 [PATCH v1 0/2] A bug fix and allow custom MySQL port Ammar Faizi
2022-12-24 22:00 ` Ammar Faizi [this message]
2022-12-24 22:59   ` [PATCH v1 1/2] telegram: listener: Fix missing MySQL error recovery function Muhammad Rizki
2022-12-24 22:00 ` [PATCH v1 2/2] Allow custom MySQL port from the env file Ammar Faizi
2022-12-24 22:57   ` Muhammad Rizki
2022-12-24 22:59     ` Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox