use bulk insert for bulk enqueue jobs

This commit is contained in:
Oliver Gorwits
2018-02-23 06:42:21 +00:00
parent 2864492ea9
commit 83752aff2c
2 changed files with 36 additions and 25 deletions

View File

@@ -1,3 +1,9 @@
2.039011 - 2018-02-23
[ENHANCEMENTS]
* use PG COPY for bulk insert of jobs with prefix
2.039010 - 2018-02-22 2.039010 - 2018-02-22
[NEW FEATURES] [NEW FEATURES]

View File

@@ -110,6 +110,7 @@ if ($device and (!$net or $net->num == 0 or $net->addr eq '0.0.0.0')) {
} }
my @hostlist = defined $device ? ($net->hostenum) : (undef); my @hostlist = defined $device ? ($net->hostenum) : (undef);
my @job_specs = ();
my $exitstatus = 0; my $exitstatus = 0;
foreach my $host (@hostlist) { foreach my $host (@hostlist) {
@@ -120,20 +121,23 @@ foreach my $host (@hostlist) {
} }
# what job are we asked to do? # what job are we asked to do?
my %job_spec = ( push @job_specs, {
action => $action, action => $action,
device => $dev, device => $dev,
port => $port, port => $port,
subaction => $extra, subaction => $extra,
); username => ($ENV{USER} || 'netdisco-do'),
};
}
if ($queue_only) { if ($queue_only) {
jq_insert({ username => ($ENV{USER} || 'netdisco-do'), %job_spec }); jq_insert( \@job_specs );
info sprintf '%s: queued at %s', $action, scalar localtime; info sprintf '%s: queued %s jobs at %s',
next; $action, (scalar @job_specs), scalar localtime;
} }
else {
my $job = App::Netdisco::Backend::Job->new({ job => 0, %job_spec }); foreach my $spec (@job_specs) {
my $job = App::Netdisco::Backend::Job->new({ job => 0, %$spec });
my $actiontext = ( my $actiontext = (
($job->device ? ('['.$job->device->ip.']') : '') . ($job->device ? ('['.$job->device->ip.']') : '') .
@@ -162,6 +166,7 @@ foreach my $host (@hostlist) {
info sprintf '%s: finished at %s', $action, scalar localtime; info sprintf '%s: finished at %s', $action, scalar localtime;
info sprintf '%s: status %s: %s', $action, $job->status, $job->log; info sprintf '%s: status %s: %s', $action, $job->status, $job->log;
$exitstatus = 1 if !$exitstatus and $job->status ne 'done'; $exitstatus = 1 if !$exitstatus and $job->status ne 'done';
}
} }
exit $exitstatus; exit $exitstatus;