shorten timeout on dns for timeoutdevices report

This commit is contained in:
Oliver Gorwits
2017-06-06 06:27:29 +01:00
parent f42ab6ff73
commit 4d0b9542d3
2 changed files with 12 additions and 4 deletions

View File

@@ -105,7 +105,7 @@ sub ipv4_from_hostname {
return undef; return undef;
} }
=head2 hostnames_resolve_async( $ips ) =head2 hostnames_resolve_async( \@ips, \@timeouts? )
This method uses a fully asynchronous and high-performance pure-perl stub This method uses a fully asynchronous and high-performance pure-perl stub
resolver C<AnyEvent::DNS>. resolver C<AnyEvent::DNS>.
@@ -114,14 +114,21 @@ Given a reference to an array of hashes will resolve the C<IPv4> or C<IPv6>
address in the C<ip>, C<alias>, or C<device> key of each hash into its address in the C<ip>, C<alias>, or C<device> key of each hash into its
hostname which will be inserted in the C<dns> key of the hash. hostname which will be inserted in the C<dns> key of the hash.
Optionally provide a set of timeout values in seconds which is also the
number of resolver attempts. The default is C<< [2,5,5] >>.
Returns the supplied reference to an array of hashes with dns values for Returns the supplied reference to an array of hashes with dns values for
addresses which resolved. addresses which resolved.
=cut =cut
sub hostnames_resolve_async { sub hostnames_resolve_async {
my $ips = shift; my ($ips, $timeouts) = @_;
return [] unless $ips and ref [] eq ref $ips;
$timeouts ||= [2,5,5];
my $skip = setting('dns')->{'no'}; my $skip = setting('dns')->{'no'};
AnyEvent::DNS::resolver->timeout(@$timeouts);
# Set up the condvar # Set up the condvar
my $done = AE::cv; my $done = AE::cv;
@@ -151,6 +158,7 @@ sub hostnames_resolve_async {
$done->recv; $done->recv;
# Remove reference to resolver so that we close sockets # Remove reference to resolver so that we close sockets
# and allow return to any instance defaults we have changed
undef $AnyEvent::DNS::RESOLVER if $AnyEvent::DNS::RESOLVER; undef $AnyEvent::DNS::RESOLVER if $AnyEvent::DNS::RESOLVER;
return $ips; return $ips;

View File

@@ -16,11 +16,11 @@ register_admin_task({
ajax '/ajax/content/admin/timedoutdevices' => require_role admin => sub { ajax '/ajax/content/admin/timedoutdevices' => require_role admin => sub {
my @set = schema('netdisco')->resultset('DeviceSkip')->search({ my @set = schema('netdisco')->resultset('DeviceSkip')->search({
deferrals => { '>' => 0 } deferrals => { '>' => 0 }
},{ rows => 50, order_by => },{ rows => (setting('dns')->{max_outstanding} || 50), order_by =>
[{ -desc => 'deferrals' }, { -asc => [qw/device backend/] }] [{ -desc => 'deferrals' }, { -asc => [qw/device backend/] }]
})->hri->all; })->hri->all;
my $results = hostnames_resolve_async(\@set); my $results = hostnames_resolve_async(\@set, [2,2,2]);
content_type('text/html'); content_type('text/html');
template 'ajax/admintask/timedoutdevices.tt', { template 'ajax/admintask/timedoutdevices.tt', {