Amazon-SQS-Simple
view release on metacpan or search on metacpan
lib/Amazon/SQS/Simple/Base.pm view on Meta::CPAN
117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
my
$escaped_params
=
$self
->_escape_params(
$params
);
my
$payload
=
join
(
'&'
,
map
{
$_
.
'='
.
$escaped_params
->{
$_
} }
keys
%$escaped_params
);
$req
->content(
$payload
);
$req
->header(
'Content-Length'
,
length
(
$payload
));
my
$signer
= AWS::Signature4->new(
-access_key
=>
$self
->{AWSAccessKeyId},
-secret_key
=>
$self
->{SecretKey});
$signer
->sign(
$req
);
$self
->_debug_log(
$req
->as_string());
$response
=
$self
->{UserAgent}->request(
$req
);
if
(
$response
->is_success) {
# note, 500 and 503 are NOT success :D
$self
->_debug_log(
$response
->content);
my
$href
= XMLin(
$response
->content,
ForceArray
=>
$force_array
,
KeyAttr
=> {});
return
$href
;
}
else
{
# advice from internal AWS support - most client libraries try 3 times in the face
# of 500 errors, so ours should too
# use exponential backoff.
if
(
$response
->code == 500 ||
$response
->code == 503) {
my
$sleep_amount
= 2 **
$try
* 50 * 1000;
$self
->_debug_log(
"Doing sleep for: $sleep_amount"
);
Time::HiRes::usleep(
$sleep_amount
);
next
;
}
die
(
"Got an error: "
.
$response
->as_string());
}
}
# if we fall out of the loop, then we have either a non-500 error or a persistent 500.
my
$msg
;
eval
{
my
$href
= XMLin(
$response
->content);
$msg
=
$href
->{Error}{Message};
};
my
$error
=
"ERROR: On calling $params->{Action}: "
.
$response
->status_line;
$error
.=
" ($msg)"
if
$msg
;
croak
$error
;
}
sub
_debug_log {
my
(
$self
,
$msg
) =
@_
;
return
unless
$self
->{_Debug};
chomp
(
$msg
);
{
$self
->{_Debug}}
$msg
.
"\n\n"
;
}
sub
_escape_params {
my
(
$self
,
$params
) =
@_
;
my
$escaped_params
= {
%$params
};
( run in 0.264 second using v1.01-cache-2.11-cpan-e5176c747c2 )