X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FDaemon.pm;h=f2b1edec8426b14d0df6f2ee612f04758e7e1fbe;hp=ed8e405ae37f603a30f495701aa456426a056759;hb=bc3729599a66921e1efd9f801222e814c626ea76;hpb=4dc6495cd974e13c9f6c3bc96c80d539e87fdd16 diff --git a/lib/Gruntmaster/Daemon.pm b/lib/Gruntmaster/Daemon.pm index ed8e405..f2b1ede 100644 --- a/lib/Gruntmaster/Daemon.pm +++ b/lib/Gruntmaster/Daemon.pm @@ -4,25 +4,22 @@ use 5.014000; use strict; use warnings; -our $VERSION = '0.001'; +our $VERSION = '5999-TRIAL'; use Gruntmaster::Daemon::Constants qw/ERR/; -use Gruntmaster::Daemon::Format qw/mkrun/; +use Gruntmaster::Daemon::Format qw/prepare_files/; use Gruntmaster::Data; -use Gruntmaster::Page::Log; use File::Basename qw/fileparse/; use File::Slurp qw/write_file/; -use File::Spec::Functions qw/devnull/; use File::Temp qw/tempdir/; -use IO::File; -use IPC::Open3 qw/open3/; use Sys::Hostname qw/hostname/; use Time::HiRes qw/time/; use Try::Tiny; -use YAML::Any qw/LoadFile DumpFile/; use Log::Log4perl qw/get_logger/; +use constant PAGE_SIZE => 10; + ################################################## sub safe_can_nodie { @@ -41,48 +38,24 @@ sub safe_can { safe_can_nodie @_ or get_logger->logdie("No such \l$type: '$name'"); } -sub prepare{ - my ($name, $format) = @_; - my $basename = fileparse $name, qr/\.[^.]*/; - get_logger->trace("Preparing file $name..."); - - open my $devnull, devnull; - open my $errors, '>>compile-error'; - my $ret = open3 $devnull, $errors, undef, 'gruntmaster-compile', $format => $basename, $name; - waitpid $ret, 0; - close $devnull; - close $errors; - die 'Compile error' if $? -} - -sub prepare_files{ - my $meta = shift; - - for my $file (values $meta->{files}) { - my ($format, $name, $content) = @{$file}{qw/format name content/}; - - $file->{run} = mkrun($format); - write_file $name, $content; - prepare $name, $format; - } -} - sub process{ my $job = shift; my @results; my @full_results = (); my $meta = {}; + our $errors = ''; try { $meta = job_inmeta $job; if (job_problem $job) { my $pbmeta = problem_meta job_problem $job; - my %files = %{$meta->{files}}; + my %files = exists $meta->{files} ? %{$meta->{files}} : (); $meta = {%$meta, %$pbmeta}; $meta->{files} = {%files, %{$pbmeta->{files}}} if exists $pbmeta->{files}; } prepare_files $meta; + chomp $errors; my ($files, $generator, $runner, $judge, $testcnt) = map { $meta->{$_} or die "Required parameter missing: $_"} qw/files generator runner judge testcnt/; @@ -128,21 +101,25 @@ sub process{ set_job_result $job, $meta->{result}; set_job_result_text $job, $meta->{result_text}; set_job_results $job, \@full_results if scalar @full_results; + set_job_errors $job, $errors; - my $log = $meta->{contest} ? "ct/$meta->{contest}/log" : 'log'; - PUBLISH gensrc => $job; + my $log = $Gruntmaster::Data::contest ? "ct/$Gruntmaster::Data::contest/log" : 'log'; + + PUBLISH gensrc => ($Gruntmaster::Data::contest // '') . ".$job"; PUBLISH genpage => "$log/job/$job.html"; PUBLISH genpage => "$log/index.html"; PUBLISH genpage => "$log/st.html"; - my $page = ($job + Gruntmaster::Page::Log::PAGE_SIZE - 1) / Gruntmaster::Page::Log::PAGE_SIZE; + my $page = ($job + PAGE_SIZE - 1) / PAGE_SIZE; PUBLISH genpage => "$log/@{[$page - 1]}.html"; PUBLISH genpage => "$log/$page.html"; PUBLISH genpage => "$log/@{[$page + 1]}.html"; } sub got_job{ - my $job = shift; - get_logger->debug("Taking job $job..."); + $_[0] =~ /^(\w*)\.(\d+)$/; + my $job = $2; + local $Gruntmaster::Data::contest = $1 if $1; + get_logger->debug("Taking job $job@{[defined $1 ? \" of contest $1\" : '']}..."); if (set_job_daemon $job, hostname . ":$$") { get_logger->debug("Succesfully taken job $job"); process $job; @@ -162,48 +139,32 @@ sub run{ 1; __END__ -# Below is stub documentation for your module. You'd better edit it! =head1 NAME -Gruntmaster::Daemon - Perl extension for blah blah blah +Gruntmaster::Daemon - Gruntmaster 6000 Online Judge -- daemon =head1 SYNOPSIS use Gruntmaster::Daemon; - blah blah blah + Gruntmaster::Daemon->run; =head1 DESCRIPTION -Stub documentation for Gruntmaster::Daemon, created by h2xs. It looks like the -author of the extension was negligent enough to leave the stub -unedited. - -Blah blah blah. - - -=head1 SEE ALSO - -Mention other useful documentation such as the documentation of -related modules or operating system documentation (such as man pages -in UNIX), or any relevant external documentation such as RFCs or -standards. - -If you have a mailing list set up for your module, mention it here. - -If you have a web site set up for your module, mention it here. +Gruntmaster::Daemon is the daemon component of the Gruntmaster 6000 online judge. =head1 AUTHOR -Marius Gavrilescu, Emarius@E +Marius Gavrilescu Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2013 by Marius Gavrilescu +Copyright (C) 2014 by Marius Gavrilescu -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.18.1 or, -at your option, any later version of Perl 5 you may have available. +This library is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. =cut