Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for timing out the bots
  • Loading branch information
MasterDuke17 committed Jul 23, 2016
1 parent e17c571 commit 1182968
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Perl6IRCBotable.pm
Expand Up @@ -28,7 +28,7 @@ use Cwd qw(cwd abs_path);
use Encode qw(encode_utf8 decode_utf8);
use File::Temp qw(tempfile tempdir);
use HTTP::Tiny;
use IO::Handle;
#use IO::Handle;
use IPC::Open3;
use JSON::XS;
use Net::GitHub;
Expand All @@ -41,17 +41,28 @@ use constant SOURCE => 'https://github.com/perl6/bisectbot';

$ENV{'RAKUDO_ERROR_COLOR'} = 0;

sub timeout {
return 10;
}

sub get_output {
my $self = shift;

my $out = undef;
my $wait = $self->timeout();
my $s_start = time();
my $pid = open3(undef, \*RESULT, \*RESULT, @_);
waitpid($pid, 0);
{
local $SIG{ALRM} = sub { kill 9, $pid; $out = "timed out after $wait seconds"; };
alarm $wait;
waitpid($pid, 0);
alarm 0;
}
my $s_end = time();

my $exit_status = $? >> 8;

my $out = do { local $/; <RESULT> };
$out = do { local $/; <RESULT> } unless defined $out;
chomp $out if defined $out;

return ($out, $exit_status, $s_end - $s_start)
Expand Down
4 changes: 4 additions & 0 deletions benchable.pl
Expand Up @@ -36,6 +36,10 @@ package Benchable;

my $name = 'benchable';

sub timeout {
return 200;
}

sub process_message {
my ($self, $message, $body) = @_;

Expand Down
4 changes: 4 additions & 0 deletions bisectable.pl
Expand Up @@ -34,6 +34,10 @@ package Bisectable;
my $commit_tester = abs_path('./test-commit');
my $build_lock = abs_path('./lock');

sub timeout {
return 200;
}

sub process_message {
my ($self, $message, $body) = @_;

Expand Down
4 changes: 4 additions & 0 deletions committable.pl
Expand Up @@ -31,6 +31,10 @@ package Committable;

my $name = 'committable';

sub timeout {
return 50;
}

sub process_message {
my ($self, $message, $body) = @_;

Expand Down

0 comments on commit 1182968

Please sign in to comment.