summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2016-02-23 17:57:24 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2016-02-23 17:57:24 +0200
commit8ca7584fa456e64d01fc931c715b9f905aa59e22 (patch)
treeb159af0b49822f7009c1f8c9f33782037a7ea253
parent2a3948f008ff8a80ca367b238c6af13a16b9fb5b (diff)
Add retry attempts for weird errors
-rw-r--r--taulubot.py20
1 files 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