I created a very simple endpoint on my Flask application that, once received a request, should send a message to a telegram chat. The problem is that sometimes the response could be Timed out
and in that i case i would need to wait 5 seconds and then try to send the message again.
The problem with this, is that i would have to use time.sleep(5)
, which will result in the function being blocked, so any other request will have to wait for the current action to finish. How can i solve this? Maybe using an Async function?
Here is my code:
@app.route('/<id>/', methods=['GET'])
def Send(id):
Content = request.data.decode('UTF-8')
try:
Query = Data.query.filter_by(uid=id).first_or_404(description='None')
updater.bot.send_message(chat_id=Query.uid, text=Content)
except Exception as e:
if str(e) == 'Timed out':
time.sleep(5)
updater.bot.send_message(chat_id=Query.uid, text=Content)