From fffe0a3b502fa43c3b836264bd1a7ca63f5b8aaa Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 17 Oct 2023 21:22:51 +0200 Subject: telegram-chat: retry on fetch failure... ... and exit with a warning. --- telegram-chat.rsc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/telegram-chat.rsc b/telegram-chat.rsc index c17394a..7486276 100644 --- a/telegram-chat.rsc +++ b/telegram-chat.rsc @@ -47,13 +47,22 @@ $WaitFullyConnected; $LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; } -:local Data; -:do { - :set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ - ("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=" . \ - $TelegramChatOffset->0 . "&allowed_updates=%5B%22message%22%5D") as-value ]->"data"); -} on-error={ - $LogPrintExit2 debug $0 ("Failed getting updates from Telegram.") true; +:local Data false; +:for I from=2 to=0 do={ + :if ($Data = false) do={ + :do { + :set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ + ("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=" . \ + $TelegramChatOffset->0 . "&allowed_updates=%5B%22message%22%5D") as-value ]->"data"); + } on-error={ + $LogPrintExit2 debug $0 ("Fetch failed, " . $I . " retries pending.") false; + :delay 2s; + } + } +} + +:if ($Data = false) do={ + $LogPrintExit2 warning $0 ("Failed getting updates from Telegram.") true; } :local UpdateID 0; -- cgit v1.2.3-70-g09d2