]>
iEval git - gruntmaster-daemon.git/blob - lib/Gruntmaster/Daemon.pm
1 package Gruntmaster
::Daemon
;
7 our $VERSION = '5999.000_001';
9 use Gruntmaster
::Daemon
::Constants qw
/ERR/;
10 use Gruntmaster
::Daemon
::Format qw
/prepare_files/;
11 use Gruntmaster
::Data
;
13 use File
::Basename qw
/fileparse/;
14 use File
::Temp qw
/tempdir/;
15 use Sys
::Hostname qw
/hostname/;
16 use Time
::HiRes qw
/time/;
18 use Log
::Log4perl qw
/get_logger/;
20 use constant PAGE_SIZE
=> 10;
22 ##################################################
25 my ($type, $sub, $name) = @_;
27 return unless $name =~ /^\w+$/;
29 my $pkg = __PACKAGE__
. "::${type}::${name}";
30 eval "require $pkg" or get_logger
->warn("Error while requiring $pkg: $@");
35 my ($type, $sub, $name) = @_;
37 safe_can_nodie
@_ or get_logger
->logdie("No such \l$type: '$name'");
44 my @full_results = ();
48 $meta = job_inmeta
$job;
49 if (job_problem
$job) {
50 my $pbmeta = problem_meta job_problem
$job;
51 my %files = exists $meta->{files
} ?
%{$meta->{files
}} : ();
52 $meta = {%$meta, %$pbmeta};
53 $meta->{files
} = {%files, %{$pbmeta->{files
}}} if exists $pbmeta->{files
};
59 my ($files, $generator, $runner, $judge, $testcnt) = map { $meta->{$_} or die "Required parameter missing: $_"} qw
/files generator runner judge testcnt/;
61 $generator = safe_can Generator
=> generate
=> $generator;
62 $runner = safe_can Runner
=> run
=> $runner;
63 $judge = safe_can Judge
=> judge
=> $judge;
65 for my $test (1 .. $testcnt) {
66 my $start_time = time;
69 $generator->($test, $meta);
70 $result = $runner->($test, $meta);
73 unless (ref $result) {
75 $result = [ERR
, $result];
80 get_logger
->trace("Test $test result is " . $result->[1]);
81 push @full_results, {id
=> $test, result
=> $result->[0], result_text
=> $result->[1], time => time - $start_time}
83 get_logger
->trace("Test $test result is $result");
84 push @full_results, {id
=> $test, result
=> 0, result_text
=> $result, time => time - $start_time}
86 push @results, $result;
87 last if $meta->{judge
} eq 'Absolute' && ref $result
90 my %results = $judge->(@results);
91 $meta->{$_} = $results{$_} for keys %results;
96 $meta->{result_text
} = $_;
99 get_logger
->info("Job result: " . $meta->{result_text
});
100 set_job_result
$job, $meta->{result
};
101 set_job_result_text
$job, $meta->{result_text
};
102 set_job_results
$job, \
@full_results if scalar @full_results;
103 set_job_errors
$job, $errors;
105 my $log = $Gruntmaster::Data
::contest ?
"ct/$Gruntmaster::Data::contest/log" : 'log';
107 PUBLISH gensrc
=> ($Gruntmaster::Data
::contest
// '') . ".$job";
108 PUBLISH genpage
=> "$log/job/$job.html";
109 PUBLISH genpage
=> "$log/index.html";
110 PUBLISH genpage
=> "$log/st.html";
111 my $page = ($job + PAGE_SIZE
- 1) / PAGE_SIZE
;
112 PUBLISH genpage
=> "$log/@{[$page - 1]}.html";
113 PUBLISH genpage
=> "$log/$page.html";
114 PUBLISH genpage
=> "$log/@{[$page + 1]}.html";
118 $_[0] =~ /^(\w*)\.(\d+)$/;
120 local $Gruntmaster::Data
::contest
= $1 if $1;
121 get_logger
->debug("Taking job $job@{[defined $1 ? \" of contest $1\" : '']}...");
122 if (set_job_daemon
$job, hostname
. ":$$") {
123 get_logger
->debug("Succesfully taken job $job");
125 get_logger
->debug("Job $job done");
127 get_logger
->debug("Job $job already taken");
132 Log
::Log4perl
->init('/etc/gruntmasterd/gruntmasterd-log.conf');
133 get_logger
->info("gruntmasterd $VERSION started");
134 chdir tempdir
'gruntmasterd.XXXX', CLEANUP
=> 1, TMPDIR
=> 1;
135 SUBSCRIBE jobs
=> \
&got_job
;
136 WAIT_FOR_MESSAGES
86400 while 1
144 Gruntmaster::Daemon - Gruntmaster 6000 Online Judge -- daemon
148 use Gruntmaster::Daemon;
149 Gruntmaster::Daemon->run;
153 Gruntmaster::Daemon is the daemon component of the Gruntmaster 6000 online judge.
157 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
159 =head1 COPYRIGHT AND LICENSE
161 Copyright (C) 2014 by Marius Gavrilescu
163 This library is free software: you can redistribute it and/or modify
164 it under the terms of the GNU Affero General Public License as published by
165 the Free Software Foundation, either version 3 of the License, or
166 (at your option) any later version.
This page took 0.061144 seconds and 5 git commands to generate.