]>
Commit | Line | Data |
---|---|---|
bbf8209c | 1 | package Gruntmaster::Data; |
6c0423f4 | 2 | use 5.014; |
bbf8209c | 3 | use warnings; |
014ee8a6 | 4 | |
edfc5928 | 5 | use parent qw/Exporter/; |
b35cbc0d | 6 | our $VERSION = '5999.000_016'; |
c847ccee | 7 | our @EXPORT = qw/dbinit purge db user_list user_entry problem_list problem_entry contest_list contest_entry contest_has_problem job_list job_entry create_job standings update_status rerun_job rerun_problem take_job finish_job open_problem/; |
6dfc2864 | 8 | our @EXPORT_OK = @EXPORT; |
4ed3f8e7 | 9 | |
91203bd5 | 10 | use JSON::MaybeXS qw/decode_json/; |
edfc5928 | 11 | use HTTP::Tiny; |
3473324b | 12 | use PerlX::Maybe qw/maybe/; |
52172a1a MG |
13 | |
14 | use DBI; | |
15 | use DBIx::Simple; | |
16 | use List::Util qw/sum/; | |
17 | use SQL::Abstract; | |
014ee8a6 | 18 | |
e890b3ae | 19 | use constant PROBLEM_PUBLIC_COLUMNS => [qw/id author writer level name owner private timeout olimit value/]; |
e1250e20 | 20 | use constant JOBS_PER_PAGE => 50; |
de625c9b | 21 | |
52172a1a MG |
22 | my %statements = ( |
23 | user_list_sth => 'SELECT * FROM user_list LIMIT 200', | |
24 | user_entry_sth => 'SELECT * FROM user_data WHERE id = ?', | |
25 | ||
26 | problem_status_sth => 'SELECT problem,solved FROM problem_status WHERE owner = ?', | |
27 | contest_status_sth => 'SELECT contest,score,rank FROM contest_status WHERE owner = ?', | |
28 | ||
29 | contest_list_sth => 'SELECT * FROM contest_entry', | |
30 | contest_entry_sth => 'SELECT * FROM contest_entry WHERE id = ?', | |
52172a1a MG |
31 | contest_has_problem_sth => 'SELECT EXISTS(SELECT 1 FROM contest_problems WHERE contest = ? AND problem = ?)', |
32 | opens_sth => 'SELECT problem,owner,time FROM opens WHERE contest = ?', | |
33 | ||
34 | problem_entry_sth => 'SELECT ' . (join ',', @{PROBLEM_PUBLIC_COLUMNS()}, 'statement', 'solution') . ' FROM problems WHERE id = ?', | |
35 | limits_sth => 'SELECT format,timeout FROM limits WHERE problem = ?', | |
52172a1a MG |
36 | |
37 | job_entry_sth => 'SELECT * FROM job_entry WHERE id = ?', | |
341fb893 | 38 | |
9baaf76b | 39 | rerun_problem_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE problem = ?', |
341fb893 | 40 | rerun_job_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE id = ?', |
9dc335bd | 41 | take_job_sth => 'UPDATE jobs SET daemon=? WHERE id = (SELECT id FROM jobs WHERE daemon IS NULL LIMIT 1 FOR UPDATE) RETURNING id', |
52172a1a MG |
42 | ); |
43 | ||
50b165c3 | 44 | our $db; |
341fb893 | 45 | sub db () { $db } |
23aa7eca | 46 | |
6fb81f9a | 47 | sub dbinit { |
62a58bf3 MG |
48 | $db = DBIx::Simple->new(@_); |
49 | $db->keep_statements = 100; | |
52172a1a MG |
50 | }; |
51 | ||
52 | sub purge; | |
53 | ||
d2c2ee95 | 54 | sub _query { |
62a58bf3 | 55 | my ($stat, @extra) = @_; |
4623c9f2 | 56 | $db->query($statements{$stat}, @extra) |
52172a1a MG |
57 | } |
58 | ||
59 | my (%name_cache, %name_cache_time); | |
60 | use constant NAME_CACHE_MAX_AGE => 5; | |
61 | ||
d2c2ee95 | 62 | sub _object_name { |
62a58bf3 | 63 | my ($table, $id) = @_; |
52172a1a MG |
64 | $name_cache_time{$table} //= 0; |
65 | if (time - $name_cache_time{$table} > NAME_CACHE_MAX_AGE) { | |
66 | $name_cache_time{$table} = time; | |
67 | $name_cache{$table} = {}; | |
62a58bf3 | 68 | $name_cache{$table} = $db->select($table, 'id,name')->map; |
52172a1a MG |
69 | } |
70 | ||
71 | $name_cache{$table}{$id} | |
72 | } | |
73 | ||
74 | ||
d2c2ee95 | 75 | sub _add_names ($) { ## no critic (ProhibitSubroutinePrototypes) |
62a58bf3 | 76 | my ($el) = @_; |
ee00be0c | 77 | return unless defined $el; |
52172a1a | 78 | if (ref $el eq 'ARRAY') { |
d2c2ee95 | 79 | &_add_names ($_) for @$el ## no critic (ProhibitAmpersandSigils) |
52172a1a MG |
80 | } else { |
81 | for my $object (qw/contest owner problem/) { | |
82 | my $table = $object eq 'owner' ? 'users' : "${object}s"; | |
d2c2ee95 | 83 | $el->{"${object}_name"} = _object_name $table, $el->{$object} if defined $el->{$object} |
52172a1a MG |
84 | } |
85 | } | |
86 | ||
87 | $el | |
88 | } | |
89 | ||
d2c2ee95 | 90 | sub user_list { scalar _query('user_list_sth')->hashes } |
52172a1a MG |
91 | |
92 | sub user_entry { | |
62a58bf3 | 93 | my ($id) = @_; |
d2c2ee95 MG |
94 | my $ret = _query('user_entry_sth', $id)->hash; |
95 | $ret->{problems} = _add_names _query('problem_status_sth', $id)->hashes; | |
96 | $ret->{contests} = _add_names _query('contest_status_sth', $id)->hashes; | |
52172a1a | 97 | |
52172a1a MG |
98 | $ret; |
99 | } | |
100 | ||
52172a1a | 101 | sub problem_list { |
62a58bf3 | 102 | my (%args) = @_; |
52172a1a MG |
103 | my @columns = @{PROBLEM_PUBLIC_COLUMNS()}; |
104 | push @columns, 'solution' if $args{solution}; | |
105 | my %where; | |
106 | $where{private} = 0 unless $args{contest} || $args{private}; | |
107 | $where{'cp.contest'} = $args{contest} if $args{contest}; | |
108 | $where{owner} = $args{owner} if $args{owner}; | |
109 | ||
110 | my $table = $args{contest} ? 'problems JOIN contest_problems cp ON cp.problem = id' : 'problems'; | |
d2c2ee95 | 111 | _add_names $db->select(\$table, \@columns, \%where, 'name')->hashes |
52172a1a MG |
112 | } |
113 | ||
52172a1a | 114 | sub problem_entry { |
a1a4325a | 115 | my ($id, $contest) = @_; |
4623c9f2 | 116 | $contest = contest_entry ($contest) if $contest; |
d2c2ee95 MG |
117 | my $ret = _add_names _query(problem_entry_sth => $id)->hash; |
118 | my $limits = _query(limits_sth => $id)->hashes; | |
52172a1a MG |
119 | $ret->{limits} = $limits if @$limits; |
120 | ||
121 | if ($contest) { | |
122 | $ret->{contest_start} = $contest->{start}; | |
123 | $ret->{contest_stop} = $contest->{stop}; | |
d33e87f2 | 124 | delete $ret->{solution} |
52172a1a MG |
125 | } |
126 | ||
127 | $ret | |
128 | } | |
129 | ||
d2c2ee95 | 130 | sub contest_list { _add_names _query('contest_list_sth')->hashes } |
52172a1a | 131 | |
d2c2ee95 | 132 | sub contest_entry { _add_names _query(contest_entry_sth => $_[0])->hash } |
52172a1a | 133 | |
d2c2ee95 | 134 | sub contest_has_problem { _query('contest_has_problem_sth', @_[0, 1])->flat } |
52172a1a | 135 | |
52172a1a | 136 | sub job_list { |
62a58bf3 | 137 | my (%args) = @_; |
b69781c1 | 138 | $args{page} = int ($args{page} // 1); |
52172a1a MG |
139 | my %where = ( |
140 | maybe contest => $args{contest}, | |
141 | maybe owner => $args{owner}, | |
142 | maybe problem => $args{problem}, | |
143 | maybe result => $args{result}, | |
144 | ); | |
145 | $where{private} = 0 unless $args{private}; | |
146 | ||
62a58bf3 | 147 | my $rows = $db->select('job_entry', 'COUNT(*)', \%where)->list; |
52172a1a | 148 | my $pages = int (($rows + JOBS_PER_PAGE - 1) / JOBS_PER_PAGE); |
62a58bf3 | 149 | my ($stmt, @bind) = $db->abstract->select('job_entry', '*', \%where, {-desc => 'id'}); |
d2c2ee95 | 150 | my $jobs = _add_names $db->query("$stmt LIMIT " . JOBS_PER_PAGE . ' OFFSET ' . ($args{page} - 1) * JOBS_PER_PAGE, @bind)->hashes; |
b69781c1 | 151 | my $pageinfo = { |
52172a1a MG |
152 | current_page => $args{page}, |
153 | last_page => $pages, | |
b69781c1 MG |
154 | ($args{page} - 1) ? (previous_page => $args{page} - 1) : (), |
155 | ($args{page} < $pages) ? (next_page => $args{page} + 1) : (), | |
156 | }; | |
157 | wantarray ? ($jobs, $pageinfo) : $jobs; | |
52172a1a MG |
158 | } |
159 | ||
160 | sub job_entry { | |
d2c2ee95 | 161 | my $ret = _add_names _query(job_entry_sth => $_[0])->hash; |
4623c9f2 | 162 | $ret->{results} = decode_json $ret->{results} if $ret->{results}; |
62a58bf3 | 163 | $ret |
52172a1a MG |
164 | } |
165 | ||
52172a1a | 166 | sub create_job { |
62a58bf3 | 167 | my (%args) = @_; |
5e77eeae | 168 | $db->update('users', {lastjob => time}, {id => $args{owner}}); |
52172a1a | 169 | purge '/log/'; |
62a58bf3 | 170 | scalar $db->insert('jobs', \%args, {returning => 'id'})->list |
52172a1a MG |
171 | } |
172 | ||
01fcdebe | 173 | sub _calc_score { |
52172a1a MG |
174 | my ($mxscore, $time, $tries, $totaltime) = @_; |
175 | my $score = $mxscore; | |
4623c9f2 | 176 | $time = 300 if $time > $totaltime; # uncoverable branch true does not happen anymore (only possible if opens are broken) |
52172a1a MG |
177 | $score = ($totaltime - $time) / $totaltime * $score; |
178 | $score -= $tries / 10 * $mxscore; | |
179 | $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10; | |
180 | int $score + 0.5 | |
181 | } | |
182 | ||
183 | sub standings { | |
62a58bf3 | 184 | my ($ct) = @_; |
01fcdebe MG |
185 | my @problems = sort { $a->{value} <=> $b->{value} } @{problem_list contest => $ct}; |
186 | my %values = map { $_->{id} => $_->{value} } @problems; | |
62a58bf3 | 187 | $ct = contest_entry $ct; |
52172a1a | 188 | |
52172a1a | 189 | my (%scores, %tries, %opens); |
d2c2ee95 | 190 | my $opens = _query(opens_sth => $ct->{id}); |
52172a1a MG |
191 | while ($opens->into(my ($problem, $owner, $time))) { |
192 | $opens{$problem, $owner} = $time; | |
193 | } | |
194 | ||
7f90c3b1 MG |
195 | # result IS NULL if job was never run |
196 | # result = -2 if job is being rerun | |
197 | my %where = (contest => $ct->{id}, result => {'>=', 0}); | |
198 | my $jobs = $db->select('job_entry', '*', \%where, 'id'); | |
52172a1a MG |
199 | |
200 | while (my $job = $jobs->hash) { | |
201 | my $open = $opens{$job->{problem}, $job->{owner}} // $ct->{start}; | |
202 | my $time = $job->{date} - $open; | |
4623c9f2 | 203 | next if $time < 0; # uncoverable branch true job sent before contest is deprecated |
52172a1a MG |
204 | my $value = $values{$job->{problem}}; |
205 | my $factor = $job->{result} ? 0 : 1; | |
206 | $factor = $1 / 100 if $job->{result_text} =~ /^(\d+ )/s; | |
01fcdebe | 207 | $scores{$job->{owner}}{$job->{problem}} = int ($factor * _calc_score ($value, $time, $tries{$job->{owner}}{$job->{problem}}++, $ct->{stop} - $ct->{start})); |
52172a1a MG |
208 | } |
209 | ||
210 | my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user} } map { ## no critic (ProhibitReverseSortBlock) | |
211 | my $user = $_; | |
212 | +{ | |
213 | user => $user, | |
d2c2ee95 | 214 | user_name => _object_name(users => $user), |
52172a1a | 215 | score => sum (values %{$scores{$user}}), |
01fcdebe | 216 | scores => [map { $scores{$user}{$_->{id}} // '-'} @problems], |
52172a1a MG |
217 | } |
218 | } keys %scores; | |
219 | ||
220 | $st[0]->{rank} = 1 if @st; | |
221 | $st[$_]->{rank} = $st[$_ - 1]->{rank} + ($st[$_]->{score} < $st[$_ - 1]->{score}) for 1 .. $#st; | |
01fcdebe MG |
222 | |
223 | \@st | |
52172a1a MG |
224 | } |
225 | ||
52172a1a | 226 | sub update_status { |
1761e170 | 227 | my $jobs = $db->select('jobs', 'id,owner,problem,result', {-not_bool => 'private'}, 'id'); |
52172a1a MG |
228 | |
229 | my %hash; | |
230 | while ($jobs->into(my ($id, $owner, $problem, $result))) { | |
231 | $hash{$problem, $owner} = [$id, $result ? 0 : 1]; | |
232 | } | |
233 | ||
234 | my @problem_statuses = map { [split ($;), @{$hash{$_}} ] } keys %hash; | |
235 | ||
236 | my @contest_statuses = map { | |
237 | my $ct = $_; | |
01fcdebe | 238 | map { [$ct, $_->{user}, $_->{score}, $_->{rank}] } @{standings $ct} |
62a58bf3 MG |
239 | } $db->select('contests', 'id')->flat; |
240 | ||
241 | $db->begin; | |
242 | $db->delete('problem_status'); | |
243 | $db->query('INSERT INTO problem_status (problem,owner,job,solved) VALUES (??)', @$_) for @problem_statuses; | |
244 | $db->delete('contest_status'); | |
245 | $db->query('INSERT INTO contest_status (contest,owner,score,rank) VALUES (??)', @$_) for @contest_statuses; | |
246 | $db->commit | |
52172a1a MG |
247 | } |
248 | ||
9baaf76b S |
249 | sub rerun_problem { |
250 | my ($problem) = @_; | |
251 | _query rerun_problem_sth => $problem; | |
252 | purge '/log/'; | |
253 | } | |
254 | ||
341fb893 MG |
255 | sub rerun_job { |
256 | my ($id) = @_; | |
d2c2ee95 | 257 | _query rerun_job_sth => $id; |
341fb893 MG |
258 | purge '/log/'; |
259 | purge "/log/$id"; | |
260 | } | |
261 | ||
9dc335bd MG |
262 | sub take_job { |
263 | my ($daemon) = @_; | |
d2c2ee95 | 264 | my $id = _query(take_job_sth => $daemon)->list; |
3ceb2ad0 MG |
265 | return unless $id; |
266 | purge '/log/'; | |
267 | purge "/log/$id"; | |
268 | db->select(jobs => '*', {id => $id})->hash | |
9dc335bd MG |
269 | } |
270 | ||
271 | sub finish_job { | |
272 | my ($job, $private, %args) = @_; | |
273 | db->update(jobs => \%args, {id => $job->{id}}); | |
3ceb2ad0 MG |
274 | purge '/log/'; |
275 | purge '/log/' . $job->{id}; | |
05fc1e15 | 276 | purge '/st/' . $job->{contest} if $job->{contest}; |
9dc335bd MG |
277 | return if $private; |
278 | my $status = { | |
279 | problem => $job->{problem}, | |
280 | owner => $job->{owner}, | |
281 | job => $job->{id}, | |
282 | solved => ($args{result} ? 0 : 1), | |
283 | }; | |
284 | eval { | |
285 | db->insert(problem_status => $status) | |
286 | } or db->update(problem_status => $status, {owner => $job->{owner}, problem => $job->{problem}}); | |
3ceb2ad0 | 287 | purge '/us/' . $job->{owner}; |
9dc335bd MG |
288 | } |
289 | ||
f7e9da17 MG |
290 | sub open_problem { |
291 | my ($contest, $problem, $owner, $time) = @_; | |
292 | my $ct = contest_entry($contest); | |
dcf7f640 MG |
293 | return unless $ct->{id} && $time >= $ct->{start} && $time < $ct->{stop}; ## no critic (ProhibitNegativeExpressionsInUnlessAndUntilConditions) |
294 | eval { db->insert(opens => { ## no critic (RequireCheckingReturnValueOfEval) | |
f7e9da17 MG |
295 | contest => $contest, |
296 | problem => $problem, | |
297 | owner => $owner, | |
298 | time => $time}) }; | |
299 | } | |
300 | ||
edfc5928 MG |
301 | my @PURGE_HOSTS = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : (); |
302 | my $ht = HTTP::Tiny->new; | |
303 | ||
de7226ca MG |
304 | sub purge { |
305 | $ht->request(PURGE => "http://$_$_[0]") for @PURGE_HOSTS; | |
306 | } | |
edfc5928 | 307 | |
f7386aab | 308 | 1; |
4a8747ef MG |
309 | |
310 | __END__ | |
311 | ||
312 | =encoding utf-8 | |
313 | ||
314 | =head1 NAME | |
315 | ||
316 | Gruntmaster::Data - Gruntmaster 6000 Online Judge -- database interface and tools | |
317 | ||
318 | =head1 SYNOPSIS | |
319 | ||
4a8747ef MG |
320 | |
321 | =head1 DESCRIPTION | |
322 | ||
23183b19 | 323 | Gruntmaster::Data is the interface to the Gruntmaster 6000 database. |
cbb36c78 | 324 | |
23183b19 | 325 | All functions are exported by default. |
cbb36c78 MG |
326 | |
327 | =over | |
328 | ||
23183b19 | 329 | =item B<dbinit>(I<@args>) |
cbb36c78 | 330 | |
23183b19 MG |
331 | This function connects to the database. I<@args> are the arguments |
332 | passed to the L<DBIx::Simple> constructor. | |
cbb36c78 | 333 | |
23183b19 | 334 | =item B<purge>(I<$url_path>) |
cbb36c78 | 335 | |
23183b19 MG |
336 | Purges a relative URL from the Varnish Cache by sending PURGE |
337 | $url_path requests to all hosts in the PURGE_HOSTS environment | |
338 | variable. | |
cbb36c78 | 339 | |
23183b19 | 340 | =item B<db> |
cbb36c78 | 341 | |
23183b19 MG |
342 | Returns a L<DBIx::Simple> object for interacting with the database |
343 | directly. Use this when no other function in this module is suitable. | |
cbb36c78 | 344 | |
23183b19 | 345 | =item B<user_list> |
cbb36c78 | 346 | |
23183b19 | 347 | Returns an arrayref of the top 200 users. |
cbb36c78 | 348 | |
23183b19 | 349 | =item B<user_entry>(I<$id>) |
cbb36c78 | 350 | |
23183b19 | 351 | Returns a hashref describing the user I<$id>. |
cbb36c78 | 352 | |
23183b19 | 353 | =item B<problem_list>([I<%args>]) |
cbb36c78 | 354 | |
23183b19 | 355 | Returns an arrayref of problems. |
cbb36c78 | 356 | |
23183b19 | 357 | Takes the following named arguments: |
cbb36c78 | 358 | |
23183b19 | 359 | =over |
cbb36c78 | 360 | |
23183b19 | 361 | =item owner |
cbb36c78 | 362 | |
23183b19 | 363 | Only show problems owned by this user |
cbb36c78 | 364 | |
23183b19 | 365 | =item contest |
cbb36c78 | 366 | |
23183b19 | 367 | Only show problems in this contest |
de625c9b | 368 | |
23183b19 | 369 | =item private |
de625c9b | 370 | |
23183b19 | 371 | If true, include private problems. Always true if contest is present. |
de625c9b | 372 | |
23183b19 | 373 | =item solution |
de625c9b | 374 | |
23183b19 | 375 | If true, include problem solutions |
de625c9b | 376 | |
23183b19 | 377 | =back |
de625c9b | 378 | |
23183b19 | 379 | =item B<problem_entry>(i<$id>, [I<$contest>]) |
de625c9b | 380 | |
23183b19 MG |
381 | Returns a hashref describing the problem I<$id>. If $contest is |
382 | present, contest start and stop times are included, and the solution | |
383 | is deleted. | |
de625c9b | 384 | |
23183b19 | 385 | =item B<contest_list> |
de625c9b | 386 | |
23183b19 | 387 | Returns an arrayref of contests. |
de625c9b | 388 | |
23183b19 | 389 | =item B<contest_entry>(I<$id>) |
de625c9b | 390 | |
23183b19 | 391 | Returns a hashref describing the contest I<$id>. |
de625c9b | 392 | |
23183b19 | 393 | =item B<contest_has_problem>(I<$contest>, I<$problem>) |
de625c9b | 394 | |
23183b19 MG |
395 | Returns true if the contest I<$contest> includes the problem |
396 | I<$problem>, false otherwise. | |
de625c9b | 397 | |
23183b19 | 398 | =item B<job_list>([I<%args>]) |
de625c9b | 399 | |
23183b19 MG |
400 | In scalar context, returns an arrayref of jobs. In list context, |
401 | returns an arrayref of jobs and a hashref of information about pages. | |
de625c9b | 402 | |
23183b19 | 403 | Takes the following named arguments: |
de625c9b MG |
404 | |
405 | =over | |
406 | ||
23183b19 | 407 | =item page |
de625c9b | 408 | |
23183b19 | 409 | Show this page of the job log. Defaults to 1. |
de625c9b | 410 | |
23183b19 | 411 | =item owner |
de625c9b | 412 | |
23183b19 | 413 | Only show jobs submitted by this user. |
de625c9b | 414 | |
23183b19 | 415 | =item contest |
de625c9b | 416 | |
23183b19 | 417 | Only show jobs submitted in this contest. |
de625c9b | 418 | |
23183b19 | 419 | =item problem |
de625c9b | 420 | |
23183b19 | 421 | Only show jobs submitted for this problem. |
de625c9b | 422 | |
23183b19 | 423 | =item result |
de625c9b | 424 | |
23183b19 MG |
425 | Only show jobs with this result (see the constants in |
426 | L<Gruntmaster::Daemon::Constants>). | |
de625c9b | 427 | |
23183b19 | 428 | =item private |
de625c9b | 429 | |
23183b19 | 430 | If true, include private jobs. Defaults to false. |
de625c9b | 431 | |
23183b19 | 432 | =back |
de625c9b | 433 | |
23183b19 | 434 | =item B<job_entry>(I<$id>) |
de625c9b | 435 | |
23183b19 | 436 | Returns a hashref describing the job I<$id>. |
de625c9b | 437 | |
23183b19 | 438 | =item B<create_job>(I<%args>) |
de625c9b | 439 | |
23183b19 MG |
440 | Insert a new job into the database. This function also updates the |
441 | lastjob field for the job's owner. | |
de625c9b | 442 | |
23183b19 | 443 | =item B<standings>(I<$ct>) |
de625c9b | 444 | |
23183b19 | 445 | Returns an arrayref of the standings of contest I<$ct>. |
de625c9b | 446 | |
23183b19 | 447 | =item B<update_status> |
de625c9b | 448 | |
23183b19 | 449 | Rebuilds the problem_status and contest_status tables. |
de625c9b | 450 | |
23183b19 | 451 | =item B<rerun_job>(I<$id>) |
de625c9b | 452 | |
23183b19 MG |
453 | Marks the job $id as pending and clears its results, so that it will |
454 | be run again by the daemon. | |
de625c9b | 455 | |
23183b19 | 456 | =item B<take_job>(I<$daemon>) |
de625c9b | 457 | |
23183b19 MG |
458 | Marks a random job as being run by I<$daemon>. Returns a hashref |
459 | describing the job, or undef if no job was available. | |
de625c9b | 460 | |
23183b19 | 461 | =item B<finish_job>(I<$job>, I<$private>, I<%results>) |
de625c9b | 462 | |
23183b19 MG |
463 | Updates the job $job with the results in %results. If $private is |
464 | false, also updates the problem_status table. | |
de625c9b | 465 | |
f7e9da17 MG |
466 | =item B<open_problem>(I<$contest>, I<$problem>, I<$owner>, I<$time>) |
467 | ||
468 | Notes that I<$owner> has opened the problem I<$problem> of contest | |
469 | I<$contest> at time I<$time>. If the C<opens> table already contains | |
470 | this (I<$contest>, I<$problem>, I<$owner>) triplet, this function does | |
471 | nothing. | |
472 | ||
cbb36c78 | 473 | =back |
4a8747ef MG |
474 | |
475 | =head1 AUTHOR | |
476 | ||
477 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
478 | ||
479 | =head1 COPYRIGHT AND LICENSE | |
480 | ||
b35cbc0d | 481 | Copyright (C) 2014-2016 by Marius Gavrilescu |
4a8747ef | 482 | |
9d2e740e | 483 | This library is free software; you can redistribute it and/or modify |
e1b9f3dd | 484 | it under the same terms as Perl itself, either Perl version 5.20.1 or, |
9d2e740e | 485 | at your option, any later version of Perl 5 you may have available. |
4a8747ef MG |
486 | |
487 | ||
488 | =cut |