X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FDaemon.pm;h=40529b26d505a6cf7019c6e9d4f4b38bd0260c71;hp=1d8cb8b41c80b18cebba926f702ca670e05e6c45;hb=3f07cf69f93b1aba2729103ea7ecf71cfc23d884;hpb=ab436d78d4cbe271d15676e5dac7b757a30d9537 diff --git a/lib/Gruntmaster/Daemon.pm b/lib/Gruntmaster/Daemon.pm index 1d8cb8b..40529b2 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"; @@ -158,12 +151,11 @@ sub got_job{ } sub run{ - Log::Log4perl->init('log.conf'); + Log::Log4perl->init('/etc/gruntmasterd-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;