From c4f9810e7d2caaf2f730e3830ebef8d8788939ea Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 20 Mar 2019 12:15:09 +0000 Subject: [PATCH] allow store() to pick the best status of any connecting worker --- lib/App/Netdisco/Backend/Job.pm | 29 ++++++++++++++++--- .../Netdisco/Worker/Plugin/Arpnip/Nodes.pm | 8 +++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/App/Netdisco/Backend/Job.pm b/lib/App/Netdisco/Backend/Job.pm index ea28c258..75879326 100644 --- a/lib/App/Netdisco/Backend/Job.pm +++ b/lib/App/Netdisco/Backend/Job.pm @@ -81,14 +81,35 @@ sub cancel { return Status->error($msg); } +=head2 best_status + +Find the best status so far. The process is to track back from the last worker +and find the highest scoring status, skipping the check phase. + +=cut + +sub best_status { + my $job = shift; + my $cur_level = 0; + my $cur_status = ''; + + foreach my $status (reverse @{ $job->_statuslist }) { + next if $status->phase + and $status->phase !~ m/^(?:early|main|store|late)$/; + + if ($status->level >= $cur_level) { + $cur_level = $status->level; + $cur_status = $status->status; + } + } + + return $cur_status; +} + =head2 finalise_status Find the best status and log it into the job's C and C slots. -The process is to track back from the last worker and find the best status, -which is C in early or main phases, or else any status in any non-user -phase. - =cut sub finalise_status { diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm index 50af14c6..b6122f35 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm @@ -35,7 +35,9 @@ register_worker({ phase => 'store' }, sub { $device->ip, scalar @{ vars->{'v6arps'} }; $device->update({last_arpnip => \$now}); - return Status->done("Ended arpnip for $device"); + + my $status = $job->best_status; + return Status->$status("Ended arpnip for $device"); }); register_worker({ phase => 'main', driver => 'snmp' }, sub { @@ -53,7 +55,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { push @{ vars->{'v6arps'} }, @{get_arps_snmp($device, $snmp->ipv6_n2p_mac, $snmp->ipv6_n2p_addr) }; - return Status->info("Gathered arp caches from $device"); + return Status->done("Gathered arp caches from $device"); }); # get an arp table (v4 or v6) @@ -97,7 +99,7 @@ register_worker({ phase => 'main', driver => 'cli' }, sub { push @{ vars->{'v6arps'} }, grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps; - return Status->info("Gathered arp caches from $device"); + return Status->done("Gathered arp caches from $device"); }); sub get_arps_cli {