rapierorg / telegram-bot-swift

Telegram Bot SDK for Swift (unofficial)
https://github.com/rapierorg/telegram-bot-swift/wiki
Apache License 2.0
375 stars 63 forks source link

How to recover from error on `nextUpdateSync` #55

Closed zapko closed 2 years ago

zapko commented 6 years ago

In all the examples and documentation if method nextUpdateSync returns nil. Proposed way to behave is to log error and exit. But what to do if I want to recover from error by, for instance, restarting bot after 5 minutes. Can you give an example of how it can be done?

It is important to me because sometimes telegram servers return 504, and I don't want to shut down bot because of that.

cipi1965 commented 6 years ago

You could setup something like supervisord to manage bot process, you can configure restart retries.

zmeyc commented 6 years ago

For example (will retry in 5 sec):

#!/bin/bash
for (( ; ; ))
do
  ./bot
  sleep 5
done
zapko commented 6 years ago

Thanks, that’s a neat solution!

But in my case telegram bot itself is not the main part of the program it is used as a terminal to do input/output with the running business-logic. I would like to avoid whole app restarting if I/O received recoverable error.