rename init stage to check
This commit is contained in:
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Device 'is_arpnipable_now';
|
use App::Netdisco::Util::Device 'is_arpnipable_now';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use Dancer::Plugin::DBIC 'schema';
|
|||||||
use Time::HiRes 'gettimeofday';
|
use Time::HiRes 'gettimeofday';
|
||||||
use NetAddr::MAC ();
|
use NetAddr::MAC ();
|
||||||
|
|
||||||
register_worker({ stage => 'init', driver => 'snmp' }, sub {
|
register_worker({ stage => 'check', driver => 'snmp' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my %queued = map {$_ => 1} jq_queued('arpnip');
|
my %queued = map {$_ => 1} jq_queued('arpnip');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Device 'delete_device';
|
use App::Netdisco::Util::Device 'delete_device';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
||||||
return Status->error('Missing device (-d).') if !defined $device;
|
return Status->error('Missing device (-d).') if !defined $device;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Device 'is_discoverable_now';
|
use App::Netdisco::Util::Device 'is_discoverable_now';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Dancer::Plugin::DBIC 'schema';
|
|||||||
use NetAddr::IP::Lite ':lower';
|
use NetAddr::IP::Lite ':lower';
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
register_worker({ stage => 'init', driver => 'snmp' }, sub {
|
register_worker({ stage => 'check', driver => 'snmp' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my %queued = map {$_ => 1} jq_queued('discover');
|
my %queued = map {$_ => 1} jq_queued('discover');
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
use App::Netdisco::Util::Statistics 'update_stats';
|
use App::Netdisco::Util::Statistics 'update_stats';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
if (setting('expire_devices') and setting('expire_devices') > 0) {
|
if (setting('expire_devices') and setting('expire_devices') > 0) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
return Status->error('nbtstat failed: unable to interpret device param')
|
return Status->error('nbtstat failed: unable to interpret device param')
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Graph ();
|
use App::Netdisco::Util::Graph ();
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
App::Netdisco::Util::Graph::graph();
|
App::Netdisco::Util::Graph::graph();
|
||||||
return Status->done('Generated graph data.');
|
return Status->done('Generated graph data.');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Device 'is_macsuckable_now';
|
use App::Netdisco::Util::Device 'is_macsuckable_now';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use Dancer::Plugin::DBIC 'schema';
|
|||||||
use Time::HiRes 'gettimeofday';
|
use Time::HiRes 'gettimeofday';
|
||||||
use Scope::Guard 'guard';
|
use Scope::Guard 'guard';
|
||||||
|
|
||||||
register_worker({ stage => 'init', driver => 'snmp' }, sub {
|
register_worker({ stage => 'check', driver => 'snmp' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my %queued = map {$_ => 1} jq_queued('macsuck');
|
my %queued = map {$_ => 1} jq_queued('macsuck');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::NodeMonitor ();
|
use App::Netdisco::Util::NodeMonitor ();
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
App::Netdisco::Util::NodeMonitor::monitor();
|
App::Netdisco::Util::NodeMonitor::monitor();
|
||||||
return Status->done('Generated monitor data.');
|
return Status->done('Generated monitor data.');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Device 'is_macsuckable';
|
use App::Netdisco::Util::Device 'is_macsuckable';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
return Status->error('nbtstat failed: unable to interpret device param')
|
return Status->error('nbtstat failed: unable to interpret device param')
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use App::Netdisco::Util::Node 'is_nbtstatable';
|
|||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
use Time::HiRes 'gettimeofday';
|
use Time::HiRes 'gettimeofday';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $host = $job->device->ip;
|
my $host = $job->device->ip;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
my %queued = map {$_ => 1} jq_queued('nbtstat');
|
my %queued = map {$_ => 1} jq_queued('nbtstat');
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use Dancer ':syntax';
|
|||||||
use App::Netdisco::Worker::Plugin;
|
use App::Netdisco::Worker::Plugin;
|
||||||
use aliased 'App::Netdisco::Worker::Status';
|
use aliased 'App::Netdisco::Worker::Status';
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use NetAddr::IP qw/:rfc3021 :lower/;
|
use NetAddr::IP qw/:rfc3021 :lower/;
|
||||||
use App::Netdisco::Util::Device qw/get_device renumber_device/;
|
use App::Netdisco::Util::Device qw/get_device renumber_device/;
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
||||||
return Status->error('Missing device (-d).') if !defined $device;
|
return Status->error('Missing device (-d).') if !defined $device;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
use Data::Printer ();
|
use Data::Printer ();
|
||||||
use App::Netdisco::Transport::SNMP;
|
use App::Netdisco::Transport::SNMP;
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
||||||
return Status->error('Missing device (-d).') if !defined $device;
|
return Status->error('Missing device (-d).') if !defined $device;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
use App::Netdisco::Util::Statistics ();
|
use App::Netdisco::Util::Statistics ();
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
App::Netdisco::Util::Statistics::update_stats();
|
App::Netdisco::Util::Statistics::update_stats();
|
||||||
return Status->done('Updated statistics.');
|
return Status->done('Updated statistics.');
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ register_worker({ stage => 'second' }, sub {
|
|||||||
return Status->done('Test (second) ran successfully.');
|
return Status->done('Test (second) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker({ stage => 'init' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (init) ran successfully.';
|
debug 'Test (check) ran successfully.';
|
||||||
return Status->done('Test (init) ran successfully.');
|
return Status->done('Test (check) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker({ stage => 'first' }, sub {
|
register_worker({ stage => 'first' }, sub {
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ sub run {
|
|||||||
@{ (setting('_nd2worker_hooks') || []) };
|
@{ (setting('_nd2worker_hooks') || []) };
|
||||||
|
|
||||||
foreach my $phase ("nd2_${action}", @phase_hooks) {
|
foreach my $phase ("nd2_${action}", @phase_hooks) {
|
||||||
foreach my $stage (qw/init first second/) {
|
foreach my $stage (qw/check first second/) {
|
||||||
my $hookname = "${phase}_${stage}";
|
my $hookname = "${phase}_${stage}";
|
||||||
next unless scalar @{ $store->get_hooks_for($hookname) };
|
next unless scalar @{ $store->get_hooks_for($hookname) };
|
||||||
$self->run_workers($hookname);
|
$self->run_workers($hookname);
|
||||||
return if $stage eq 'init' and $self->jobstat->not_ok;
|
return if $stage eq 'check' and $self->jobstat->not_ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ sub run_workers {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $hook = shift or return $self->jobstat->error('missing hook param');
|
my $hook = shift or return $self->jobstat->error('missing hook param');
|
||||||
my $store = Dancer::Factory::Hook->instance();
|
my $store = Dancer::Factory::Hook->instance();
|
||||||
my $init = ($hook =~ m/_init$/);
|
my $check = ($hook =~ m/_check$/);
|
||||||
|
|
||||||
return unless scalar @{ $store->get_hooks_for($hook) };
|
return unless scalar @{ $store->get_hooks_for($hook) };
|
||||||
debug "running workers for hook: $hook";
|
debug "running workers for hook: $hook";
|
||||||
@@ -87,11 +87,11 @@ sub run_workers {
|
|||||||
my $retval = $worker->($self->job);
|
my $retval = $worker->($self->job);
|
||||||
# could die or return undef or a scalar or Status or another class
|
# could die or return undef or a scalar or Status or another class
|
||||||
$self->jobstat($retval)
|
$self->jobstat($retval)
|
||||||
if $init and ref $retval eq 'App::Netdisco::Worker::Status';
|
if $check and ref $retval eq 'App::Netdisco::Worker::Status';
|
||||||
}
|
}
|
||||||
catch { $self->jobstat->error($_) if $init };
|
catch { $self->jobstat->error($_) if $check };
|
||||||
|
|
||||||
last if $init and $self->jobstat->is_ok;
|
last if $check and $self->jobstat->is_ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user