From f3ad9692b18669c216897ce1ce0a668c59c3889a Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Wed, 15 Jan 2014 12:48:19 +0200 Subject: [PATCH] Use centralised pub/sub and reduce number of chdirs --- lib/Gruntmaster/Daemon.pm | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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; -- 2.39.2