auto debug-log worker return messages
This commit is contained in:
@@ -6,19 +6,16 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
register_worker({ stage => 'main' }, sub {
|
register_worker({ stage => 'main' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (main) ran successfully.';
|
|
||||||
return Status->done('Test (main) ran successfully (1).');
|
return Status->done('Test (main) ran successfully (1).');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker({ stage => 'check' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (check) ran successfully.';
|
|
||||||
return Status->done('Test (check) ran successfully.');
|
return Status->done('Test (check) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker({ stage => 'early' }, sub {
|
register_worker({ stage => 'early' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (early) ran successfully.';
|
|
||||||
return Status->error('Test (early) ran successfully.');
|
return Status->error('Test (early) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,25 +6,21 @@ use aliased 'App::Netdisco::Worker::Status';
|
|||||||
|
|
||||||
register_worker({ stage => 'main' }, sub {
|
register_worker({ stage => 'main' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (main) ran successfully.';
|
|
||||||
return Status->done('Test (main) ran successfully (2).');
|
return Status->done('Test (main) ran successfully (2).');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker({ stage => 'check' }, sub {
|
register_worker({ stage => 'check' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (check) ran successfully.';
|
|
||||||
return Status->done('Test (check) ran successfully.');
|
return Status->done('Test (check) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker({ stage => 'early' }, sub {
|
register_worker({ stage => 'early' }, sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (early) ran successfully.';
|
|
||||||
return Status->done('Test (early) ran successfully.');
|
return Status->done('Test (early) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
register_worker(sub {
|
register_worker(sub {
|
||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
debug 'Test (undefined) ran successfully.';
|
|
||||||
return Status->error('Test (undefined) ran successfully.');
|
return Status->error('Test (undefined) ran successfully.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -62,11 +62,14 @@ sub run {
|
|||||||
my $guard = guard { set(device_auth => \@userconf) };
|
my $guard = guard { set(device_auth => \@userconf) };
|
||||||
set(device_auth => \@newuserconf);
|
set(device_auth => \@newuserconf);
|
||||||
|
|
||||||
|
# run check phase
|
||||||
|
# optional - but if there are workers then one MUST return done
|
||||||
my $store = Dancer::Factory::Hook->instance();
|
my $store = Dancer::Factory::Hook->instance();
|
||||||
$self->run_workers('nd2_core_check');
|
$self->run_workers('nd2_core_check');
|
||||||
return if scalar @{ $store->get_hooks_for('nd2_core_check') }
|
return if scalar @{ $store->get_hooks_for('nd2_core_check') }
|
||||||
and $self->jobstat->not_ok;
|
and $self->jobstat->not_ok;
|
||||||
|
|
||||||
|
# run other phases
|
||||||
$self->jobstat( Status->error('no worker succeeded during main phase') );
|
$self->jobstat( Status->error('no worker succeeded during main phase') );
|
||||||
$self->run_workers("nd2_core_${_}") for qw/early main user/;
|
$self->run_workers("nd2_core_${_}") for qw/early main user/;
|
||||||
}
|
}
|
||||||
@@ -85,15 +88,21 @@ sub run_workers {
|
|||||||
# 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
|
||||||
my $retval = $worker->($self->job);
|
my $retval = $worker->($self->job);
|
||||||
|
|
||||||
# update (save) the status if we're in check or main phases
|
if (ref $retval eq 'App::Netdisco::Worker::Status') {
|
||||||
# check because it's a gatekeeper, main because it's the retval
|
# update (save) the status if we're in check or main phases
|
||||||
$self->jobstat($retval)
|
# because these logs can end up in the job queue as status message
|
||||||
if ($phase =~ m/^(?:check|main)$/)
|
$self->jobstat($retval)
|
||||||
and ref $retval eq 'App::Netdisco::Worker::Status'
|
if ($phase =~ m/^(?:check|main)$/)
|
||||||
and $retval->level >= $self->jobstat->level;
|
and $retval->level >= $self->jobstat->level;
|
||||||
|
|
||||||
|
debug $retval->log if $retval->log;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
# errors at most phases are ignored
|
# errors at most phases are ignored
|
||||||
catch { $self->jobstat->error($_) if $phase eq 'check' };
|
catch {
|
||||||
|
$self->jobstat->error($_) if $phase eq 'check';
|
||||||
|
debug $_ if $_;
|
||||||
|
};
|
||||||
|
|
||||||
# any successful check is a GO!
|
# any successful check is a GO!
|
||||||
last if $phase eq 'check' and $self->jobstat->is_ok;
|
last if $phase eq 'check' and $self->jobstat->is_ok;
|
||||||
|
|||||||
Reference in New Issue
Block a user