finish refactor to new desired behaviour (buggy?)
This commit is contained in:
@@ -43,7 +43,7 @@ register 'register_worker' => sub {
|
||||
my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef);
|
||||
my $only = (exists $workerconf->{only} ? $workerconf->{only} : undef);
|
||||
|
||||
return $job->defer('worker is not applicable to this device')
|
||||
return $job->add_status( Status->defer('worker is not applicable to this device') )
|
||||
if ($no and check_acl_no($job->device, $no))
|
||||
or ($only and not check_acl_only($job->device, $only));
|
||||
|
||||
@@ -59,7 +59,7 @@ register 'register_worker' => sub {
|
||||
}
|
||||
|
||||
# per-device action but no device creds available
|
||||
return $job->defer('deferred job with no device creds')
|
||||
return $job->add_status( Status->defer('deferred job with no device creds') )
|
||||
if 0 == scalar @newuserconf;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,24 +4,24 @@ use Dancer ':syntax';
|
||||
use App::Netdisco::Worker::Plugin;
|
||||
use aliased 'App::Netdisco::Worker::Status';
|
||||
|
||||
register_worker({ phase => 'main' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (main) ran successfully (1).');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'check' }, sub {
|
||||
register_worker({ phase => 'check', driver => 'snmp' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (check) ran successfully.');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'early' }, sub {
|
||||
register_worker({ phase => 'check', priority => 100 }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->error('Test (early) ran successfully.');
|
||||
return Status->done('Test (check 100) ran successfully.');
|
||||
});
|
||||
|
||||
register_worker(sub {
|
||||
register_worker({ phase => 'check', priority => 120 }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->noop('Test (undefined) ran successfully.');
|
||||
return Status->done('Test (check 120) ran successfully.');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'check', driver => 'eapi' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (check eapi) ran successfully.');
|
||||
});
|
||||
|
||||
true;
|
||||
|
||||
@@ -4,14 +4,9 @@ use Dancer ':syntax';
|
||||
use App::Netdisco::Worker::Plugin;
|
||||
use aliased 'App::Netdisco::Worker::Status';
|
||||
|
||||
register_worker({ phase => 'main' }, sub {
|
||||
register_worker({ phase => 'early' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (main) ran successfully (2).');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'check' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (check) ran successfully.');
|
||||
return Status->error('Test (early) ran successfully.');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'early' }, sub {
|
||||
@@ -19,9 +14,24 @@ register_worker({ phase => 'early' }, sub {
|
||||
return Status->done('Test (early) ran successfully.');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'main' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (main) ran successfully (1).');
|
||||
});
|
||||
|
||||
register_worker({ phase => 'main' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->done('Test (main) ran successfully (2).');
|
||||
});
|
||||
|
||||
register_worker(sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->error('Test (undefined) ran successfully.');
|
||||
return Status->noop('Test (user) ran successfully.');
|
||||
});
|
||||
|
||||
register_worker(sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
return Status->error('Test (user) ran successfully.');
|
||||
});
|
||||
|
||||
true;
|
||||
|
||||
@@ -5,6 +5,7 @@ use Dancer::Factory::Hook;
|
||||
|
||||
use App::Netdisco::Util::Permission qw/check_acl_no check_acl_only/;
|
||||
use App::Netdisco::Util::Device 'get_device';
|
||||
use aliased 'App::Netdisco::Worker::Status';
|
||||
|
||||
use Try::Tiny;
|
||||
use Module::Load ();
|
||||
@@ -43,7 +44,7 @@ sub run {
|
||||
}
|
||||
|
||||
# per-device action but no device creds available
|
||||
return $job->defer('deferred job with no device creds')
|
||||
return $job->add_status( Status->defer('deferred job with no device creds') )
|
||||
if 0 == scalar @newuserconf;
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ sub run {
|
||||
my $configguard = guard { set(device_auth => \@userconf) };
|
||||
set(device_auth => \@newuserconf);
|
||||
|
||||
# finalise job status when we exit XXX FIXME
|
||||
# finalise job status when we exit
|
||||
my $statusguard = guard { $job->finalise_status };
|
||||
|
||||
# run check phase and if there are workers then one MUST be successful
|
||||
@@ -65,19 +66,20 @@ sub run {
|
||||
sub run_workers {
|
||||
my $self = shift;
|
||||
my $job = $self->job or die error 'no job in worker job slot';
|
||||
my $hook = shift or return $job->error('missing hook param'); # XXX FIXME
|
||||
my $hook = shift
|
||||
or return $job->add_status( Status->error('missing hook param') );
|
||||
|
||||
my $store = Dancer::Factory::Hook->instance();
|
||||
(my $phase = $hook) =~ s/^nd2_core_//;
|
||||
|
||||
return unless scalar @{ $store->get_hooks_for($hook) };
|
||||
debug "=> running workers for phase: $phase";
|
||||
$job->enter_phase($phase);
|
||||
|
||||
foreach my $worker (@{ $store->get_hooks_for($hook) }) {
|
||||
try { $job->add_status( $worker->($job) ) }
|
||||
catch {
|
||||
debug "=> $_" if $_;
|
||||
$job->error($_);
|
||||
$job->add_status( Status->error($_) );
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ has 'status' => (
|
||||
default => undef,
|
||||
);
|
||||
|
||||
has 'log' => (
|
||||
has [qw/log phase/] => (
|
||||
is => 'rw',
|
||||
default => '',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user