NAME
Plack::Middleware::Timeout
SYNOPSIS
my $app = sub { ... };
Plack::Middleeare::Timeout->wrap(
$app,
timeout => sub { ... } || 120,
# optional callback to set the custom response
response => sub {
my ($response_obj) = @_;
$response_obj->code(HTTP_REQUEST_TIMEOUT);
$response_obj->body( encode_json({
timeout => 1,
other_info => {...},
}));
return $plack_response;
}
);
DESCRIPTION
Timeout any plack requests at an arbitrary time.
PARAMETERS
- timeout
-
Numeric value accepted by subroutine defined in Time::HiRes::alarm, default 120 seconds.
- response
-
Optional subroutine which will be exeuted when timeout is reached. The subref receives a Plack::Response object as argument. If the response subref isn't defined, we resolve to emitting a warning:
'Terminated request for uri '%s' due to timeout (%ds)'
- soft_timeout
-
Same as timeout, except this value will be checked after the call to the app has completed. See also
on_soft_timeout
below. - on_soft_timeout
-
optional coderef that'll get executed when we established, that time required to serve the response was longer than a value provided in the soft_timeout parameter. If soft_timeout is set but no on_soft_timeout coderef is provided, we're going to issue a warning as follows; the response will be returned as normal.
'Soft timeout reached for uri '%s' (soft timeout: %ds) request took %ds'
AUTHOR
Tomasz Czepiel <tjmc@cpan.org>
LICENCE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.