X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FDaemon.pm;h=a9a6d9971a52a863d765996c6ceadfdc5f0ccb25;hp=a4d1902b0cfa6fb9f36e196ea976da3a863996e6;hb=d6a1ae0d77398b2a7ed967e10e8420ac7d9980e5;hpb=ad77b7d3dee6e61405535dd0dabd117398731ad1 diff --git a/lib/Gruntmaster/Daemon.pm b/lib/Gruntmaster/Daemon.pm index a4d1902..a9a6d99 100644 --- a/lib/Gruntmaster/Daemon.pm +++ b/lib/Gruntmaster/Daemon.pm @@ -4,24 +4,27 @@ use 5.014000; use strict; use warnings; -our $VERSION = '0.001'; +our $VERSION = '5999.000_002'; use Gruntmaster::Daemon::Constants qw/ERR/; use Gruntmaster::Daemon::Format qw/prepare_files/; use Gruntmaster::Data; use File::Basename qw/fileparse/; -use File::Slurp qw/write_file/; use File::Temp qw/tempdir/; use Sys::Hostname qw/hostname/; use Time::HiRes qw/time/; use Try::Tiny; use Log::Log4perl qw/get_logger/; +use LWP::UserAgent; use constant PAGE_SIZE => 10; ################################################## +my $ua = LWP::UserAgent->new; +my @purge_hosts = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : (); + sub safe_can_nodie { my ($type, $sub, $name) = @_; @@ -38,6 +41,13 @@ sub safe_can { safe_can_nodie @_ or get_logger->logdie("No such \l$type: '$name'"); } +sub purge { + for my $host (@purge_hosts) { + my $req = HTTP::Request->new(PURGE => "http://$host$_[0]"); + $ua->request($req) + } +} + sub process{ my $job = shift; @@ -48,9 +58,20 @@ sub process{ try { $meta = job_inmeta $job; if (job_problem $job) { - my $pbmeta = problem_meta job_problem $job; + local $_ = job_problem $job; + my $pbmeta = problem_meta; my %files = exists $meta->{files} ? %{$meta->{files}} : (); - $meta = {%$meta, %$pbmeta}; + $meta = { + %$meta, + problem => $_, + (defined problem_generator() ? (generator => problem_generator) : ()), + (defined problem_runner() ? (runner => problem_runner) : ()), + (defined problem_judge() ? (judge => problem_judge) : ()), + (defined problem_testcnt() ? (testcnt => problem_testcnt) : ()), + (defined problem_timeout() ? (timeout => problem_timeout) : ()), + (defined problem_olimit() ? (olimit => problem_olimit) : ()), + %$pbmeta + }; $meta->{files} = {%files, %{$pbmeta->{files}}} if exists $pbmeta->{files}; } @@ -113,6 +134,11 @@ sub process{ PUBLISH genpage => "$log/@{[$page - 1]}.html"; PUBLISH genpage => "$log/$page.html"; PUBLISH genpage => "$log/@{[$page + 1]}.html"; + + purge "/$log/job/$job"; + purge "/$log/"; + purge "/$log/st"; + purge "/$log/$_" for $page - 1, $page, $page + 1; } sub got_job{ @@ -139,48 +165,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