fix fqdn global to use settings instead
This commit is contained in:
@@ -22,8 +22,14 @@ BEGIN {
|
|||||||
|
|
||||||
use App::Netdisco;
|
use App::Netdisco;
|
||||||
use Dancer qw/:moose :script/;
|
use Dancer qw/:moose :script/;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
warning sprintf "App::Netdisco %s backend", ($App::Netdisco::VERSION || 'HEAD');
|
warning sprintf "App::Netdisco %s backend", ($App::Netdisco::VERSION || 'HEAD');
|
||||||
|
|
||||||
|
# this can take a few seconds - only do it once
|
||||||
|
use Net::Domain 'hostfqdn';
|
||||||
|
info 'resolving backend hostname...';
|
||||||
|
setting('workers')->{'backend'} ||= (hostfqdn || 'fqdn-undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
use App::Netdisco::Util::Backend;
|
use App::Netdisco::Util::Backend;
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ use App::Netdisco::Util::Device
|
|||||||
qw/is_discoverable is_macsuckable is_arpnipable/;
|
qw/is_discoverable is_macsuckable is_arpnipable/;
|
||||||
use App::Netdisco::Backend::Job;
|
use App::Netdisco::Backend::Job;
|
||||||
|
|
||||||
|
|
||||||
use Net::Domain 'hostfqdn';
|
|
||||||
use Module::Load ();
|
use Module::Load ();
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
|
|
||||||
@@ -30,21 +28,17 @@ our @EXPORT_OK = qw/
|
|||||||
/;
|
/;
|
||||||
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK );
|
||||||
|
|
||||||
# this can take a few seconds - only do it once
|
|
||||||
our $fqdn = undef;
|
|
||||||
|
|
||||||
sub _getsome {
|
sub _getsome {
|
||||||
my ($num_slots, $where) = @_;
|
my ($num_slots, $where) = @_;
|
||||||
return () if ((!defined $num_slots) or ($num_slots < 1));
|
return () if ((!defined $num_slots) or ($num_slots < 1));
|
||||||
return () if ((!defined $where) or (ref {} ne ref $where));
|
return () if ((!defined $where) or (ref {} ne ref $where));
|
||||||
|
|
||||||
$fqdn ||= (hostfqdn || 'localhost');
|
|
||||||
my $jobs = schema('netdisco')->resultset('Admin');
|
my $jobs = schema('netdisco')->resultset('Admin');
|
||||||
|
|
||||||
my $rs = $jobs->search({
|
my $rs = $jobs->search({
|
||||||
status => 'queued',
|
status => 'queued',
|
||||||
device => { '-not_in' =>
|
device => { '-not_in' =>
|
||||||
$jobs->skipped($fqdn, setting('workers')->{'max_deferrals'},
|
$jobs->skipped(setting('workers')->{'backend'},
|
||||||
|
setting('workers')->{'max_deferrals'},
|
||||||
setting('workers')->{'retry_after'})
|
setting('workers')->{'retry_after'})
|
||||||
->columns('device')->as_query },
|
->columns('device')->as_query },
|
||||||
%$where,
|
%$where,
|
||||||
@@ -75,11 +69,9 @@ sub jq_getsomep {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub jq_locked {
|
sub jq_locked {
|
||||||
$fqdn ||= (hostfqdn || 'localhost');
|
|
||||||
my @returned = ();
|
my @returned = ();
|
||||||
|
|
||||||
my $rs = schema('netdisco')->resultset('Admin')
|
my $rs = schema('netdisco')->resultset('Admin')
|
||||||
->search({status => "queued-$fqdn"});
|
->search({ status => ('queued-'. setting('workers')->{'backend'}) });
|
||||||
|
|
||||||
while (my $job = $rs->next) {
|
while (my $job = $rs->next) {
|
||||||
push @returned, App::Netdisco::Backend::Job->new({ $job->get_columns });
|
push @returned, App::Netdisco::Backend::Job->new({ $job->get_columns });
|
||||||
@@ -117,7 +109,6 @@ sub _get_denied_actions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub jq_warm_thrusters {
|
sub jq_warm_thrusters {
|
||||||
$fqdn ||= (hostfqdn || 'localhost');
|
|
||||||
my @devices = schema('netdisco')->resultset('Device')->all;
|
my @devices = schema('netdisco')->resultset('Device')->all;
|
||||||
my $rs = schema('netdisco')->resultset('DeviceSkip');
|
my $rs = schema('netdisco')->resultset('DeviceSkip');
|
||||||
my %actionset = ();
|
my %actionset = ();
|
||||||
@@ -128,10 +119,10 @@ sub jq_warm_thrusters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
$rs->search({ backend => $fqdn })->delete;
|
$rs->search({ backend => setting('workers')->{'backend'} })->delete;
|
||||||
$rs->populate([
|
$rs->populate([
|
||||||
map {{
|
map {{
|
||||||
backend => $fqdn,
|
backend => setting('workers')->{'backend'},
|
||||||
device => $_,
|
device => $_,
|
||||||
actionset => $actionset{$_},
|
actionset => $actionset{$_},
|
||||||
}} keys %actionset
|
}} keys %actionset
|
||||||
@@ -141,7 +132,6 @@ sub jq_warm_thrusters {
|
|||||||
|
|
||||||
sub jq_lock {
|
sub jq_lock {
|
||||||
my $job = shift;
|
my $job = shift;
|
||||||
$fqdn ||= (hostfqdn || 'localhost');
|
|
||||||
my $happy = false;
|
my $happy = false;
|
||||||
|
|
||||||
if ($job->device) {
|
if ($job->device) {
|
||||||
@@ -152,7 +142,7 @@ sub jq_lock {
|
|||||||
my @badactions = _get_denied_actions($job->device);
|
my @badactions = _get_denied_actions($job->device);
|
||||||
if (scalar @badactions) {
|
if (scalar @badactions) {
|
||||||
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
|
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
|
||||||
backend => $fqdn, device => $job->device,
|
backend => setting('workers')->{'backend'}, device => $job->device,
|
||||||
},{ key => 'device_skip_pkey' })->add_to_actionset(@badactions);
|
},{ key => 'device_skip_pkey' })->add_to_actionset(@badactions);
|
||||||
|
|
||||||
return false if scalar grep {$_ eq $job->action} @badactions;
|
return false if scalar grep {$_ eq $job->action} @badactions;
|
||||||
@@ -163,12 +153,13 @@ sub jq_lock {
|
|||||||
try {
|
try {
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
schema('netdisco')->resultset('Admin')
|
schema('netdisco')->resultset('Admin')
|
||||||
->search({job => $job->job}, {for => 'update'})
|
->search({ job => $job->job }, { for => 'update' })
|
||||||
->update({ status => "queued-$fqdn" });
|
->update({ status => ('queued-'. setting('workers')->{'backend'}) });
|
||||||
|
|
||||||
return unless
|
return unless
|
||||||
schema('netdisco')->resultset('Admin')
|
schema('netdisco')->resultset('Admin')
|
||||||
->count({job => $job->job, status => "queued-$fqdn"});
|
->count({ job => $job->job,
|
||||||
|
status => ('queued-'. setting('workers')->{'backend'}) });
|
||||||
|
|
||||||
# remove any duplicate jobs, needed because we have race conditions
|
# remove any duplicate jobs, needed because we have race conditions
|
||||||
# when queueing jobs of a type for all devices
|
# when queueing jobs of a type for all devices
|
||||||
@@ -192,7 +183,6 @@ sub jq_lock {
|
|||||||
|
|
||||||
sub jq_defer {
|
sub jq_defer {
|
||||||
my $job = shift;
|
my $job = shift;
|
||||||
$fqdn ||= (hostfqdn || 'localhost');
|
|
||||||
my $happy = false;
|
my $happy = false;
|
||||||
|
|
||||||
# note this taints all actions on the device. for example if both
|
# note this taints all actions on the device. for example if both
|
||||||
@@ -206,7 +196,7 @@ sub jq_defer {
|
|||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
if ($job->device) {
|
if ($job->device) {
|
||||||
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
|
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
|
||||||
backend => $fqdn, device => $job->device,
|
backend => setting('workers')->{'backend'}, device => $job->device,
|
||||||
},{ key => 'device_skip_pkey' })->increment_deferrals;
|
},{ key => 'device_skip_pkey' })->increment_deferrals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +216,6 @@ sub jq_defer {
|
|||||||
|
|
||||||
sub jq_complete {
|
sub jq_complete {
|
||||||
my $job = shift;
|
my $job = shift;
|
||||||
$fqdn ||= (hostfqdn || 'localhost');
|
|
||||||
my $happy = false;
|
my $happy = false;
|
||||||
|
|
||||||
# lock db row and update to show job is done/error
|
# lock db row and update to show job is done/error
|
||||||
@@ -239,7 +228,7 @@ sub jq_complete {
|
|||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
if ($job->device) {
|
if ($job->device) {
|
||||||
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
|
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
|
||||||
backend => $fqdn, device => $job->device,
|
backend => setting('workers')->{'backend'}, device => $job->device,
|
||||||
},{ key => 'device_skip_pkey' })->update({ deferrals => 0 });
|
},{ key => 'device_skip_pkey' })->update({ deferrals => 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user