X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FDaemon.pm;h=46da60b9da8355dd6d9999859d923f10c5371e3c;hp=1d8cb8b41c80b18cebba926f702ca670e05e6c45;hb=f3ad9692b18669c216897ce1ce0a668c59c3889a;hpb=ab436d78d4cbe271d15676e5dac7b757a30d9537 diff --git a/lib/Gruntmaster/Daemon.pm b/lib/Gruntmaster/Daemon.pm index 1d8cb8b..46da60b 100644 --- a/lib/Gruntmaster/Daemon.pm +++ b/lib/Gruntmaster/Daemon.pm @@ -9,16 +9,14 @@ our $VERSION = '0.001'; use Gruntmaster::Daemon::Constants qw/ERR/; use Gruntmaster::Daemon::Format qw/mkrun/; use Gruntmaster::Page qw/generate/; -use Gruntmaster::Data qw/job_inmeta job_problem problem_meta set_job_daemon set_job_result set_job_result_text set_job_results/; +use Gruntmaster::Data qw/job_inmeta job_problem problem_meta set_job_daemon set_job_result set_job_result_text set_job_results SUBSCRIBE WAIT_FOR_MESSAGES/; -use Cwd qw/cwd/; 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 Redis; use Sys::Hostname qw/hostname/; use Time::HiRes qw/time/; use Try::Tiny; @@ -70,12 +68,8 @@ sub prepare_files{ } } -my $tempdir; - sub process{ my $job = shift; - my $rootdir = cwd; - chdir $tempdir; my @results; my @full_results = (); @@ -137,7 +131,6 @@ sub process{ set_job_result_text $job, $meta->{result_text}; set_job_results $job, \@full_results if scalar @full_results; - chdir $rootdir; my $log = $meta->{contest} ? "ct/$meta->{contest}/log" : 'log'; write_file "$log/src/$job." . Gruntmaster::Page::Log::FORMAT_EXTENSION->{$meta->{files}{prog}{format}}, $meta->{files}{prog}{content}; generate "$log/job/$job.html"; @@ -160,10 +153,9 @@ sub got_job{ sub run{ Log::Log4perl->init('log.conf'); get_logger->info("gruntmasterd $VERSION started"); - $tempdir = tempdir 'gruntmasterd.XXXX', CLEANUP => 1, TMPDIR => 1; - my $redis = Redis->new; - $redis->subscribe('jobs', \&got_job); - $redis->wait_for_messages(0) while 1 + chdir tempdir 'gruntmasterd.XXXX', CLEANUP => 1, TMPDIR => 1; + SUBSCRIBE jobs => \&got_job; + WAIT_FOR_MESSAGES 86400 while 1 } 1;