From d584cb7d797a1be3fdf6814a9ac990a4fe3f80d6 Mon Sep 17 00:00:00 2001 From: Egg Date: Thu, 22 Jun 2023 08:14:30 +0200 Subject: [PATCH] improve sleep. add error logging to db --- active_bots/telegrambot.py | 2 +- backend.py | 5 ++--- db.py | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 1972664..3bd3ac2 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -89,7 +89,7 @@ class TelegramBot(Bot): try: for subscriber_id in user.get_telegram_subscribers(): tb.send_message(subscriber_id, text).wait() - sleep(0.1) + sleep(0.5) except Exception: logger.error('Error telegramming: ' + user.get_city() + ': ' + str(report.id), exc_info=True) diff --git a/backend.py b/backend.py index 5bc9dac..6e36788 100755 --- a/backend.py +++ b/backend.py @@ -34,15 +34,14 @@ if __name__ == '__main__': while True: for user in db.active_users: for bot in bots: - sleep(0.1) + sleep(5) reports = bot.crawl(user) for status in reports: - sleep(0.1) if not user.is_appropriate(status): logger.info("Inaproppriate message: %d %s %s" % (user.uid, status.author, status.text)) continue for bot2 in bots: - sleep(0.1) + sleep(1) bot2.post(user, status) logger.info("Resent: %d %s %s" % (user.uid, status.author, status.text)) except Exception: diff --git a/db.py b/db.py index 11fe6d4..bbbc64f 100644 --- a/db.py +++ b/db.py @@ -25,12 +25,14 @@ class DB(object): try: self.conn.commit() break - except sqlite3.OperationalError: + except sqlite3.OperationalError as error: # another thread may be writing, give it a chance to finish - sleep(0.1) + sleep(0.5) + logger.exception() if time() - start_time > 5: # if it takes this long, something is wrong system("rcctl restart frontend_daemon") + logger.warning("frontend_daemon is getting restarted") self.conn.commit() def close(self):