fix to work, and correct namespace check
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package App::Netdisco::Backend::Job;
|
package App::Netdisco::Backend::Job;
|
||||||
|
|
||||||
|
use Dancer qw/:moose :syntax !error/;
|
||||||
use aliased 'App::Netdisco::Worker::Status';
|
use aliased 'App::Netdisco::Worker::Status';
|
||||||
|
|
||||||
use Moo;
|
use Moo;
|
||||||
@@ -18,11 +19,10 @@ foreach my $slot (qw/
|
|||||||
username
|
username
|
||||||
userip
|
userip
|
||||||
log
|
log
|
||||||
debug
|
|
||||||
|
|
||||||
_phase
|
_last_phase
|
||||||
_namespace
|
_last_namespace
|
||||||
_priority
|
_last_priority
|
||||||
/) {
|
/) {
|
||||||
|
|
||||||
has $slot => (
|
has $slot => (
|
||||||
@@ -63,10 +63,9 @@ sub finalise_status {
|
|||||||
|
|
||||||
# fallback
|
# fallback
|
||||||
$job->status('error');
|
$job->status('error');
|
||||||
$job->log('failed to succeed at any worker!');
|
$job->log('failed to report from any worker!');
|
||||||
|
|
||||||
foreach my $status (@{ $self->_statuslist }) {
|
foreach my $status (@{ $job->_statuslist }) {
|
||||||
next unless $status->phase =~ m/^(?:early|main)$/;
|
|
||||||
if ($status->level >= $max_level) {
|
if ($status->level >= $max_level) {
|
||||||
$job->status( $status->status );
|
$job->status( $status->status );
|
||||||
$job->log( $status->log );
|
$job->log( $status->log );
|
||||||
@@ -84,11 +83,10 @@ C<done>.
|
|||||||
|
|
||||||
sub check_passed {
|
sub check_passed {
|
||||||
my $job = shift;
|
my $job = shift;
|
||||||
foreach my $status (@{ $self->_statuslist }) {
|
foreach my $status (@{ $job->_statuslist }) {
|
||||||
next unless $status->phase eq 'check';
|
return true if $status->is_ok;
|
||||||
return 1 if $status->is_ok;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 namespace_passed( \%workerconf )
|
=head2 namespace_passed( \%workerconf )
|
||||||
@@ -101,36 +99,37 @@ all workers of a higher priority level have succeeded.
|
|||||||
sub namespace_passed {
|
sub namespace_passed {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
|
|
||||||
if (defined $job->_namespace
|
if ($job->_last_namespace) {
|
||||||
and ($workerconf->{phase} eq $job->_phase)
|
foreach my $status (@{ $job->_statuslist }) {
|
||||||
and ($workerconf->{namespace} eq $job->_namespace)
|
next unless ($workerconf->{phase} eq $job->_last_phase)
|
||||||
and ($workerconf->{priority} != $job->_priority)) {
|
and ($workerconf->{namespace} eq $job->_last_namespace)
|
||||||
|
and ($workerconf->{priority} != $job->_last_priority);
|
||||||
foreach my $status (@{ $self->_statuslist }) {
|
return true if $status->is_ok;
|
||||||
next unless ($status->phase eq $job->_phase)
|
|
||||||
and ($staus->namespace eq $job->_namespace)
|
|
||||||
and ($status->priority == $job->_priority);
|
|
||||||
return 1 if $status->is_ok;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$job->_phase( $workerconf->{phase} );
|
# reset the internal status cache when the phase changes
|
||||||
$job->_namespace( $workerconf->{namespace} );
|
$job->_statuslist([]) if $job->_last_phase
|
||||||
$job->_priority( $workerconf->{priority} );
|
and $job->_last_phase ne $workerconf->{phase};
|
||||||
return 0;
|
|
||||||
|
$job->_last_phase( $workerconf->{phase} );
|
||||||
|
$job->_last_namespace( $workerconf->{namespace} );
|
||||||
|
$job->_last_priority( $workerconf->{priority} );
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 add_status
|
=head2 add_status
|
||||||
|
|
||||||
Passed an L<App::Netdisco::Worker::Status> will add it to this job's internal
|
Passed an L<App::Netdisco::Worker::Status> will add it to this job's internal
|
||||||
store.
|
status cache.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub add_status {
|
sub add_status {
|
||||||
my ($job, $status) = @_;
|
my ($job, $status) = @_;
|
||||||
return unless ref $status eq 'App::Netdisco::Worker::Status';
|
return unless ref $status eq 'App::Netdisco::Worker::Status';
|
||||||
push @{ $self->_statuslist }, $status;
|
push @{ $job->_statuslist }, $status;
|
||||||
|
debug $status->log if $status->log;
|
||||||
}
|
}
|
||||||
|
|
||||||
=head1 ADDITIONAL COLUMNS
|
=head1 ADDITIONAL COLUMNS
|
||||||
@@ -151,4 +150,4 @@ Alias for the C<subaction> column.
|
|||||||
|
|
||||||
sub extra { (shift)->subaction }
|
sub extra { (shift)->subaction }
|
||||||
|
|
||||||
1;
|
true;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ sub run {
|
|||||||
my $configguard = guard { set(device_auth => \@userconf) };
|
my $configguard = guard { set(device_auth => \@userconf) };
|
||||||
set(device_auth => \@newuserconf);
|
set(device_auth => \@newuserconf);
|
||||||
|
|
||||||
# finalise job status when we exit
|
# finalise job status when we exit XXX FIXME
|
||||||
my $statusguard = guard { $job->finalise_status };
|
my $statusguard = guard { $job->finalise_status };
|
||||||
|
|
||||||
# run check phase and if there are workers then one MUST be successful
|
# run check phase and if there are workers then one MUST be successful
|
||||||
@@ -65,7 +65,7 @@ sub run {
|
|||||||
sub run_workers {
|
sub run_workers {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $job = $self->job or die error 'no job in worker job slot';
|
my $job = $self->job or die error 'no job in worker job slot';
|
||||||
my $hook = shift or return $job->error('missing hook param');
|
my $hook = shift or return $job->error('missing hook param'); # XXX FIXME
|
||||||
|
|
||||||
my $store = Dancer::Factory::Hook->instance();
|
my $store = Dancer::Factory::Hook->instance();
|
||||||
(my $phase = $hook) =~ s/^nd2_core_//;
|
(my $phase = $hook) =~ s/^nd2_core_//;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ has 'status' => (
|
|||||||
default => undef,
|
default => undef,
|
||||||
);
|
);
|
||||||
|
|
||||||
has ['log', 'phase', 'namespace', 'priority'] => (
|
has 'log' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
default => '',
|
default => '',
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user