##################################################
-my $db = Gruntmaster::Data->connect('dbi:Pg:');
+my $db;
my $ua = LWP::UserAgent->new;
my @purge_hosts = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : ();
my $meta;
our $errors = '';
try {
- $meta = {
- problem => $jobr->problem->id,
- files => {
- prog => {
- name => 'prog.' . $jobr->extension,
- format => $jobr->format,
- content => $jobr->source,
+ if (ref $job) {
+ $meta = $job;
+ } else {
+ $meta = {
+ problem => $jobr->problem->id,
+ files => {
+ prog => {
+ name => 'prog.' . $jobr->extension,
+ format => $jobr->format,
+ content => $jobr->source,
+ },
},
- },
- map { $_ => $jobr->problem->get_column($_) } qw/generator runner judge testcnt timeout olimit/
- };
- $meta->{tests} = decode_json $jobr->problem->tests if $meta->{runner} eq 'File';
+ map { $_ => $jobr->problem->get_column($_) } qw/generator runner judge testcnt timeout olimit/
+ };
+ $meta->{tests} = decode_json $jobr->problem->tests if $meta->{runner} eq 'File';
- $meta->{files}{ver} = {
- name => 'ver.' . FORMAT_EXTENSION->{$jobr->problem->verformat},
- format => $jobr->problem->verformat,
- content => $jobr->problem->versource,
- } if $jobr->problem->verformat;
+ $meta->{files}{ver} = {
+ name => 'ver.' . FORMAT_EXTENSION->{$jobr->problem->verformat},
+ format => $jobr->problem->verformat,
+ content => $jobr->problem->versource,
+ } if $jobr->problem->verformat;
+ }
prepare_files $meta;
chomp $errors;
my %results = $judge->(@results);
$meta->{$_} = $results{$_} for keys %results;
+ $meta->{results} = \@full_results
} catch {
s,(.*) at .*,$1,;
chomp;
};
get_logger->info("Job result: " . $meta->{result_text});
+ return unless $jobr;
$jobr->update({
result => $meta->{result},
result_text => $meta->{result_text},
- results => encode_json \@full_results,
+ results => encode_json $meta->{results},
$errors ? (errors => $errors) : ()
});
}
sub run{
+ $db = Gruntmaster::Data->connect('dbi:Pg:');
Log::Log4perl->init('/etc/gruntmasterd/gruntmasterd-log.conf');
get_logger->info("gruntmasterd $VERSION started");
chdir tempdir 'gruntmasterd.XXXX', CLEANUP => 1, TMPDIR => 1;
use File::Basename qw/fileparse/;
use File::Slurp qw/read_file/;
use File::Temp qw/tempdir/;
+use Hash::Merge qw/merge/;
use List::Util qw/sum/;
use Log::Log4perl;
use Test::More;
$ENV{PATH}.=':' . cwd;
sub check_job{
- my $job = shift;
- my $jobh = get_job $job;
- my $meta = job_inmeta $job;
- $meta->{result} = $jobh->{result};
- $meta->{result_text} = $jobh->{result_text};
- $meta->{results} = $jobh->{results};
+ my $meta = shift;
if (defined $meta->{results}) {
delete $meta->{results}[$_]{time} for keys $meta->{results};
}
my $job = 0;
for my $problem (@problems) {
- my $meta = LoadFile "$problem/meta.yml";
- for (1 .. $meta->{testcnt}) {
- $meta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $meta->{generator} eq 'File';
- $meta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $meta->{runner} eq 'File';
+ my $pbmeta = LoadFile "$problem/meta.yml";
+ for (1 .. $pbmeta->{testcnt}) {
+ $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File';
+ $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} eq 'File';
}
- if (exists $meta->{files}) {
- $_->{content} = read_file "$problem/$_->{name}" for values $meta->{files}
+ if (exists $pbmeta->{files}) {
+ $_->{content} = read_file "$problem/$_->{name}" for values $pbmeta->{files}
}
- set_problem_meta scalar fileparse($problem), $meta;
TODO: {
- local $TODO = $meta->{todo} if exists $meta->{todo};
- note "Now testing problem $meta->{name} ($meta->{description})";
+ local $TODO = $pbmeta->{todo} if exists $pbmeta->{todo};
+ note "Now testing problem $pbmeta->{name} ($pbmeta->{description})";
for my $source (<$problem/tests/*>) {
my $meta = LoadFile "$source/meta.yml";
$meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
- $job++;
- set_job_inmeta $job, $meta;
- set_job_problem $job, scalar fileparse $problem;
+ $meta = merge $meta, $pbmeta;
note "Running $meta->{test_name} ($meta->{test_description})...";
my $savedcwd = cwd;
chdir $tempdir;
- Gruntmaster::Daemon::process $job;
- check_job $job;
+ Gruntmaster::Daemon::process $meta;
chdir $savedcwd;
+ check_job $meta;
}
}
}