Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
user app logger in legacy validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lane Seppala authored and lseppala committed Mar 9, 2018
1 parent c4aba6c commit cf1a907
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Conch/lib/Conch/Controller/DeviceReport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ sub process ($c) {

my ( $device, $report_id ) = record_device_report( $schema, $device_report );
my $validation_result =
validate_device( $schema, $device, $device_report, $report_id );
validate_device( $schema, $device, $device_report, $report_id, $c->app->log );

$c->status( 200, $validation_result );
}
Expand Down
14 changes: 7 additions & 7 deletions Conch/lib/Conch/Legacy/Control/Device/Validation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use Conch::Legacy::Control::Device::Environment;
use Conch::Legacy::Control::Device::Inventory;
use Conch::Legacy::Control::Device::Network;

use Mojo::Exception;
use Mojo::JSON qw(encode_json);

use Exporter 'import';
our @EXPORT = qw( validate_device );
Expand All @@ -30,7 +30,7 @@ Run device validations with a device report.
=cut

sub validate_device {
my ( $schema, $device, $device_report, $report_id ) = @_;
my ( $schema, $device, $device_report, $report_id, $logger ) = @_;

my @validations = $device_report->validations;
try {
Expand All @@ -55,7 +55,7 @@ sub validate_device {

$schema->resultset('DeviceValidate')->create(
{
device_id => $device_id,
device_id => $device->id,
report_id => $report_id,
validation => encode_json(
{
Expand All @@ -68,20 +68,20 @@ sub validate_device {
}
);

Mojo::Exception->throw(
$logger->error(
$device->id . ": Marking FAIL because exception occurred: $message" );
return { health => "FAIL", errors => [$message] };
}

my $validation_errors = $@ if $@;
if ( $validation_errors && $validation_errors->exceptions > 0 ) {
my @errors = $validation_errors->exceptions;
map { trace $_; } @errors;
warning( $device->id . ": Marking FAIL" );
$logger->warn( $device->id . ": Marking FAIL" );
$device->update( { health => "FAIL" } );
return { health => "FAIL", errors => \@errors };
}
else {
info( $device->id . ": Marking PASS" );
$logger->info( $device->id . ": Marking PASS" );
$device->update( { health => "PASS" } );
return { health => "PASS" };
}
Expand Down

0 comments on commit cf1a907

Please sign in to comment.