From ffce3cee847c7fcd11bc62acdcb690e0f9653415 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 23 May 2017 20:12:39 +0100 Subject: [PATCH] only resolve fqdn once --- lib/App/Netdisco/JobQueue/PostgreSQL.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/lib/App/Netdisco/JobQueue/PostgreSQL.pm index b3ec8dd7..0b9605b3 100644 --- a/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -30,12 +30,15 @@ our @EXPORT_OK = qw/ /; our %EXPORT_TAGS = ( all => \@EXPORT_OK ); +# this can take a few seconds - only do it once +our $fqdn = undef; + sub _getsome { my ($num_slots, $where) = @_; return () if ((!defined $num_slots) or ($num_slots < 1)); return () if ((!defined $where) or (ref {} ne ref $where)); - my $fqdn = hostfqdn || 'localhost'; + my $fqdn ||= (hostfqdn || 'localhost'); my $jobs = schema('netdisco')->resultset('Admin'); my $rs = $jobs->search({ @@ -71,7 +74,7 @@ sub jq_getsomep { } sub jq_locked { - my $fqdn = hostfqdn || 'localhost'; + my $fqdn ||= (hostfqdn || 'localhost'); my @returned = (); my $rs = schema('netdisco')->resultset('Admin') @@ -112,7 +115,7 @@ sub _get_denied_actions { } sub jq_prime_skiplist { - my $fqdn = hostfqdn || 'localhost'; + my $fqdn ||= (hostfqdn || 'localhost'); my @devices = schema('netdisco')->resultset('Device')->all; my $rs = schema('netdisco')->resultset('DeviceSkip'); my %actionset = (); @@ -136,7 +139,7 @@ sub jq_prime_skiplist { sub jq_lock { my $job = shift; - my $fqdn = hostfqdn || 'localhost'; + my $fqdn ||= (hostfqdn || 'localhost'); my $happy = false; # need to handle device discovered since backend daemon started @@ -185,7 +188,7 @@ sub jq_lock { sub jq_defer { my $job = shift; - my $fqdn = hostfqdn || 'localhost'; + my $fqdn ||= (hostfqdn || 'localhost'); my $happy = false; # note this taints all actions on the device. for example if both