Merge pull request #1137 from DeterminateSystems/runcommand-logs

Store and display the output of RunCommands
This commit is contained in:
Graham Christensen
2022-01-31 16:26:31 -05:00
committed by GitHub
16 changed files with 315 additions and 27 deletions

View File

@ -5,6 +5,10 @@ use warnings;
use parent 'Hydra::Plugin';
use experimental 'smartmatch';
use JSON::MaybeXS;
use File::Basename qw(dirname);
use File::Path qw(make_path);
use IPC::Run3;
use Try::Tiny;
sub isEnabled {
my ($self) = @_;
@ -160,10 +164,31 @@ sub buildFinished {
$runlog->started();
system("$command") == 0
or warn "notification command '$command' failed with exit status $? ($!)\n";
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog) or die "RunCommandLog not found.";
my $dir = dirname($logPath);
my $oldUmask = umask();
my $f;
$runlog->completed_with_child_error($?, $!);
try {
# file: 640, dir: 750
umask(0027);
make_path($dir);
open($f, '>', $logPath);
umask($oldUmask);
run3($command, \undef, $f, $f, { return_if_system_error => 1 }) == 1
or warn "notification command '$command' failed with exit status $? ($!)\n";
close($f);
$runlog->completed_with_child_error($?, $!);
1;
} catch {
die "Died while trying to process RunCommand (${\$runlog->uuid}): $_";
} finally {
umask($oldUmask);
};
}
}