diff options
-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); |