TT#121056 prevent cron messages while restapi is down

die with proper response body only on client errors,
or server errors other than 502, 503, 504 errors.
skip further processing silently on 502, 503, 504
(to prevent running into them again and again).

so cron messages will only pop if there is a real problem.

Change-Id: I1ee193c69ce8ea6f07fe4b228cd19bc47c2e35b6
(cherry picked from commit c133398967)
mr9.5.1
Rene Krenn 5 years ago
parent 06e6866829
commit 42216740dd

@ -118,7 +118,7 @@ sub get_data {
my @result = ();
while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success;
return [] unless check_api_error($res);
my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) {
@ -134,6 +134,19 @@ sub get_data {
return \@result;
}
sub check_api_error {
my $res = shift;
if ($res->is_success) {
return 1;
} else {
die($res->result . "\n") if (
$res->is_client_error
or ($res->is_server_error and not scalar grep { $_ == $res->code; } qw(502 503 504))
);
return 0;
}
}
sub get_email_template {
my $templates_data = get_data('/api/emailtemplates/', 'emailtemplates');
foreach my $template (@{$templates_data}) {

@ -88,7 +88,7 @@ sub get_data {
my @result = ();
while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success;
return [] unless check_api_error($res);
my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) {
@ -104,6 +104,19 @@ sub get_data {
return \@result;
}
sub check_api_error {
my $res = shift;
if ($res->is_success) {
return 1;
} else {
die($res->result . "\n") if (
$res->is_client_error
or ($res->is_server_error and not scalar grep { $_ == $res->code; } qw(502 503 504))
);
return 0;
}
}
sub get_email_template {
my $event = shift;

Loading…
Cancel
Save