use bulk insert for bulk enqueue jobs
This commit is contained in:
6
Changes
6
Changes
@@ -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]
|
||||||
|
|||||||
@@ -110,30 +110,34 @@ 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 $exitstatus = 0;
|
my @job_specs = ();
|
||||||
|
my $exitstatus = 0;
|
||||||
|
|
||||||
foreach my $host (@hostlist) {
|
foreach my $host (@hostlist) {
|
||||||
my $dev = $host ? get_device($host->addr) : undef;
|
my $dev = $host ? get_device($host->addr) : undef;
|
||||||
if ($dev and not (blessed $dev and $dev->in_storage) and $action !~ m/^discover/) {
|
if ($dev and not (blessed $dev and $dev->in_storage) and $action !~ m/^discover/) {
|
||||||
info sprintf "%s: error - Don't know device: %s", $action, $host->addr;
|
info sprintf "%s: error - Don't know device: %s", $action, $host->addr;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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.']') : '') .
|
||||||
@@ -142,13 +146,13 @@ foreach my $host (@hostlist) {
|
|||||||
|
|
||||||
# do job
|
# do job
|
||||||
try {
|
try {
|
||||||
info sprintf '%s: %s started at %s',
|
info sprintf '%s: %s started at %s',
|
||||||
$action, $actiontext, scalar localtime;
|
$action, $actiontext, scalar localtime;
|
||||||
$worker->run($job);
|
$worker->run($job);
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$job->status('error');
|
$job->status('error');
|
||||||
$job->log("error running job: $_");
|
$job->log("error running job: $_");
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($job->log eq 'failed to report from any worker!' and not $job->only_namespace) {
|
if ($job->log eq 'failed to report from any worker!' and not $job->only_namespace) {
|
||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user