1LWP::UserAgent::DetermiUnseedr(3C)ontributed Perl DocumeLnWtPa:t:iUosnerAgent::Determined(3)
2
3
4

NAME

6       LWP::UserAgent::Determined - a virtual browser that retries errors
7

SYNOPSIS

9         use strict;
10         use LWP::UserAgent::Determined;
11         my $browser = LWP::UserAgent::Determined->new;
12         my $response = $browser->get($url, headers... );
13

DESCRIPTION

15       This class works just like LWP::UserAgent (and is based on it, by being
16       a subclass of it), except that when you use it to get a web page but
17       run into a possibly-temporary error (like a DNS lookup timeout), it'll
18       wait a few seconds and retry a few times.
19
20       It also adds some methods for controlling exactly what errors are
21       considered retry-worthy and how many times to wait and for how many
22       seconds, but normally you needn't bother about these, as the default
23       settings are relatively sane.
24

METHODS

26       This module inherits all of LWP::UserAgent's methods, and adds the
27       following.
28
29       $timing_string = $browser->timing();
30       $browser->timing( "10,30,90" )
31           The "timing" method gets or sets the string that controls how many
32           times it should retry, and how long the pauses should be.
33
34           If you specify empty-string, this means not to retry at all.
35
36           If you specify a string consisting of a single number, like "10",
37           that means that if the first request doesn't succeed, then
38           "$browser->get(...)" (or any other method based on "request" or
39           "simple_request") should wait 10 seconds and try again (and if that
40           fails, then it's final).
41
42           If you specify a string with several numbers in it (like
43           "10,30,90"), then that means $browser can retry as that many times
44           (i.e., one initial try, plus a maximum of the three retries,
45           because three numbers there), and that it should wait first those
46           numbers of seconds each time.  So "$browser->timing( "10,30,90" )"
47           basically means:
48
49             try the request; return it unless it's a temporary-looking error;
50             sleep 10;
51             retry the request; return it unless it's a temporary-looking error;
52             sleep 30;
53             retry the request; return it unless it's a temporary-looking error;
54             sleep 90  the request;
55             return it;
56
57           The default value is "1,3,15".
58
59       $http_codes_hr = $browser->codes_to_determinate();
60           This returns the hash that is the set of HTTP codes that merit a
61           retry (like 500 and 408, but unlike 404 or 200).  You can delete or
62           add entries like so;
63
64             $http_codes_hr = $browser->codes_to_determinate();
65             delete $http_codes_hr->{408};
66             $http_codes_hr->{567} = 1;
67
68           (You can actually set a whole new hashset with
69           "$browser->codes_to_determinate($new_hr)", but there's usually no
70           benefit to that as opposed to the above.)
71
72           The current default is 408 (Timeout) plus some 5xx codes.
73
74       $browser->before_determined_callback()
75       $browser->before_determined_callback( \&some_routine );
76       $browser->after_determined_callback()
77       $browser->after_determined_callback( \&some_routine );
78           These read (first two) or set (second two) callbacks that are
79           called before the actual HTTP/FTP/etc request is made.  By default,
80           these are set to undef, meaning nothing special is called.  If you
81           want to alter try requests, or inspect responses before any
82           retrying is considered, you can set up these callbacks.
83
84           The arguments passed to these routines are:
85
86           0: the current $browser object
87           1: an arrayref to the list of timing pauses (based on
88           $browser->timing)
89           2: the duration of the number of seconds we'll pause if this
90           request fails this time, or undef if this is the last chance.
91           3: the value of $browser->codes_to_determinate
92           4: an arrayref of the arguments we pass to
93           LWP::UserAgent::simple_request (the first of which is the request
94           object)
95           (5): And, only for after_determined_callback, the response we just
96           got.
97
98           Example use:
99
100             $browser->before_determined_callback( sub {
101               print "Trying ", $_[4][0]->uri, " ...\n";
102             });
103

IMPLEMENTATION

105       This class works by overriding LWP::UserAgent's "simple_request" method
106       with its own around-method that just loops.  See the source of this
107       module; it's straightforward.  Relatively.
108

SEE ALSO

110       LWP, LWP::UserAgent
111
113       Copyright 2004, Sean M. Burke, all rights reserved.  This program is
114       free software; you can redistribute it and/or modify it under the same
115       terms as Perl itself.
116
117       This program is distributed in the hope that it will be useful, but
118       without any warranty; without even the implied warranty of
119       merchantability or fitness for a particular purpose.
120

AUTHOR

122       Originally created by Sean M. Burke, "sburke@cpan.org"
123
124       Currently maintained by Jesse Vincent "jesse@fsck.com"
125
126
127
128perl v5.32.0                      2020-07-28     LWP::UserAgent::Determined(3)
Impressum