Created
November 30, 2022 17:10
-
-
Save JJ/b8e9785c2f4d4cffb17b87e6aa0024a0 to your computer and use it in GitHub Desktop.
Server post with retries by Humberto Massa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constant NUMBER-OF-RETRIES = 3; # YMMV | |
constant COOLING-OFF-PERIOD = 2; # this is plenty to stall this thread | |
sub server-post($data) { | |
our $cro; | |
do { | |
my $r = await $cro.post: "{SERVER-URI}/{DATA-PATH}", body => $data; | |
my $count = NUMBER-OF-RETRIES; | |
while $count-- and $r.status == 503|401 { | |
sleep COOLING-OFF-PERIOD; | |
server-login if $r.status == 401; | |
$r = await $cro.post: "{SERVER-URI}/{DATA-PATH}", body => $data; | |
} | |
await $r.body | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment