allow store() to pick the best status of any connecting worker
This commit is contained in:
@@ -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<status> and C<log> slots.
|
||||
|
||||
The process is to track back from the last worker and find the best status,
|
||||
which is C<done> in early or main phases, or else any status in any non-user
|
||||
phase.
|
||||
|
||||
=cut
|
||||
|
||||
sub finalise_status {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user