better use of new status class

This commit is contained in:
Oliver Gorwits
2017-09-03 17:58:03 +01:00
parent 8675bf62c6
commit 4def0af0b0
3 changed files with 36 additions and 10 deletions

View File

@@ -36,4 +36,32 @@ Returns the logical inversion of C<ok>.
sub not_ok { return (not $_[0]->ok) }
=head2 status
Returns text equivalent of C<done>, C<defer>, or C<error>.
=cut
sub status {
my $self = shift;
return (
$self->done ? 'done'
: $self->defer ? 'defer'
: 'error';
);
}
=head2 update_job
Updates an L<App::Netdisco::Backend::Job> with status and message.
=cut
sub update_job {
my $self = shift;
my $job = shift or return;
$job->status( $self->status );
$job->log( $self->message );
}
1;

View File

@@ -39,9 +39,8 @@ sub worker_body {
$wid, $job->job, $job->summary;
info sprintf "pol (%s): starting %s job(%s) at %s",
$wid, $action, $job->job, $job->started;
my ($status, $log) = $self->$action($job);
$job->status($status);
$job->log($log);
my $status = $self->$action($job); # TODO
$status->update_job($job);
}
catch {
$job->status('error');