diff options
author | Guillermo Ramos | 2020-02-24 13:03:02 +0100 |
---|---|---|
committer | Guillermo Ramos | 2020-02-24 13:03:02 +0100 |
commit | 5ec7bc555bbfcbd22a1095bc4936568898f894da (patch) | |
tree | 3b45dc1ffdf625a8b206d659ce7a03abfd43e3a6 | |
parent | 4ab6e09e1197f1a0e9fce9a3a3a5ce821c0d6194 (diff) | |
download | tgutils-5ec7bc555bbfcbd22a1095bc4936568898f894da.tar.gz |
tgserver: Catch errors w/ exponential backoff wait
-rwxr-xr-x | tgserver | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -37,9 +37,19 @@ $TOKEN ||= fetch_token() or my $cache = TgLib::Cache->new($logger); my $api = TgLib::Api->new($TOKEN, $logger); +my $sleep_exp = 1; while (1) { # FIXME magic timeout - foreach my $update (@{$api->get_updates(3600, $cache->offset)}) { + my @updates = eval { @{$api->get_updates(3600, $cache->offset)} }; + if ($@) { + chomp $@; + print "ERROR: $@\n"; + sleep($sleep_exp); + $sleep_exp *= 2 unless $sleep_exp >= 32; + } else { + $sleep_exp = 1; + }; + foreach my $update (@updates) { # Cache current offset $cache->offset($update->{'update_id'}+1); |