Skip to content

Instantly share code, notes, and snippets.

@JJ
Created November 30, 2022 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/b8e9785c2f4d4cffb17b87e6aa0024a0 to your computer and use it in GitHub Desktop.
Save JJ/b8e9785c2f4d4cffb17b87e6aa0024a0 to your computer and use it in GitHub Desktop.
Server post with retries by Humberto Massa
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