blib/lib/App/Netdisco/Worker/Plugin/Discover.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 43 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Worker::Plugin::Discover;
2  
3 use Dancer ':syntax';
4 use App::Netdisco::Worker::Plugin;
5 use aliased 'App::Netdisco::Worker::Status';
6  
7 use App::Netdisco::Util::Device 'is_discoverable_now';
8 use Time::HiRes 'gettimeofday';
9  
10 register_worker({ phase => 'check' }, sub {
11 my ($job, $workerconf) = @_;
12 my $device = $job->device;
13  
14 return Status->error('discover failed: unable to interpret device param')
15 unless defined $device;
16  
17 return Status->error("discover failed: no device param (need -d ?)")
18 if $device->ip eq '0.0.0.0';
19  
20 return Status->info("discover skipped: $device is not discoverable")
21 unless is_discoverable_now($device);
22  
23 # would be possible just to use LOCALTIMESTAMP on updated records, but by using this
24 # same value for them all, we can if we want add a job at the end to
25 # select and do something with the updated set (see set archive, below)
26 vars->{'timestamp'} = ($job->is_offline and $job->entered)
27 ? (schema('netdisco')->storage->dbh->quote($job->entered) .'::timestamp')
28 : 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
29  
30 return Status->done('Discover is able to run.');
31 });
32  
33 true;