From 8ca7584fa456e64d01fc931c715b9f905aa59e22 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 23 Feb 2016 17:57:24 +0200 Subject: Add retry attempts for weird errors --- taulubot.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/taulubot.py b/taulubot.py index fad1a68..cc52c77 100644 --- a/taulubot.py +++ b/taulubot.py @@ -65,7 +65,6 @@ TOKEN = sys.argv[1] bot = telepot.Bot(TOKEN) logging.warning("Connected with token {}".format(TOKEN)) - last_user_by_chat_id = {} done_list = [] @@ -82,12 +81,19 @@ def handle(msg): if is_taulu_command(msg_text): logging.warning("Taulu command found!") - try: - taulu_id = last_user_by_chat_id[chat_id] - logging.warning("Running taulu for user id {}".format(taulu_id)) - run_taulu(chat_id, taulu_id) - except KeyError: - logging.error("No chat id found in chat dict. Maybe no previous messages in the chat?") + attempt, ATTEMPTS = 0, 3 + while attempt < ATTEMPTS: + try: + taulu_id = last_user_by_chat_id[chat_id] + logging.warning("Running taulu for user id {}".format(taulu_id)) + run_taulu(chat_id, taulu_id) + break + except KeyError: + logging.error("No chat id found in chat dict. Maybe no previous messages in the chat?") + break + except: + logging.error("Error occured during process. Retrying... (attempt {})".format(attempt)) + attempt += 1 last_user_by_chat_id[chat_id] = user_id -- cgit v1.3