X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FData.pm;h=dd6c73faa8d880a25527c3dac51239d338cea6fb;hb=c847cceeb2343de57094432e172fba8f9404e312;hp=3b634ca6f3ebf935bf94af74fad46bc6c10c4a28;hpb=23183b1989f7a63b9033810433ad8ec97c3f7ab9;p=gruntmaster-data.git diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 3b634ca..dd6c73f 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -3,8 +3,8 @@ use 5.014; use warnings; use parent qw/Exporter/; -our $VERSION = '5999.000_013'; -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 take_job finish_job/; ## no critic (ProhibitAutomaticExportation) +our $VERSION = '5999.000_015'; +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/; our @EXPORT_OK = @EXPORT; use JSON::MaybeXS qw/decode_json/; @@ -36,6 +36,7 @@ my %statements = ( job_entry_sth => 'SELECT * FROM job_entry WHERE id = ?', + rerun_problem_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE problem = ?', rerun_job_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE id = ?', take_job_sth => 'UPDATE jobs SET daemon=? WHERE id = (SELECT id FROM jobs WHERE daemon IS NULL LIMIT 1 FOR UPDATE) RETURNING id', ); @@ -242,6 +243,12 @@ sub update_status { $db->commit } +sub rerun_problem { + my ($problem) = @_; + _query rerun_problem_sth => $problem; + purge '/log/'; +} + sub rerun_job { my ($id) = @_; _query rerun_job_sth => $id; @@ -252,12 +259,18 @@ sub rerun_job { sub take_job { my ($daemon) = @_; my $id = _query(take_job_sth => $daemon)->list; - return $id ? db->select(jobs => '*', {id => $id})->hash : undef; + return unless $id; + purge '/log/'; + purge "/log/$id"; + db->select(jobs => '*', {id => $id})->hash } sub finish_job { my ($job, $private, %args) = @_; db->update(jobs => \%args, {id => $job->{id}}); + purge '/log/'; + purge '/log/' . $job->{id}; + purge '/st/' . $job->{contest} if $job->{contest}; return if $private; my $status = { problem => $job->{problem}, @@ -268,6 +281,18 @@ sub finish_job { eval { db->insert(problem_status => $status) } or db->update(problem_status => $status, {owner => $job->{owner}, problem => $job->{problem}}); + purge '/us/' . $job->{owner}; +} + +sub open_problem { + my ($contest, $problem, $owner, $time) = @_; + my $ct = contest_entry($contest); + return unless $ct->{id} && $time >= $ct->{start} && $time < $ct->{stop}; ## no critic (ProhibitNegativeExpressionsInUnlessAndUntilConditions) + eval { db->insert(opens => { ## no critic (RequireCheckingReturnValueOfEval) + contest => $contest, + problem => $problem, + owner => $owner, + time => $time}) }; } my @PURGE_HOSTS = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : (); @@ -435,6 +460,13 @@ describing the job, or undef if no job was available. Updates the job $job with the results in %results. If $private is false, also updates the problem_status table. +=item B(I<$contest>, I<$problem>, I<$owner>, I<$time>) + +Notes that I<$owner> has opened the problem I<$problem> of contest +I<$contest> at time I<$time>. If the C table already contains +this (I<$contest>, I<$problem>, I<$owner>) triplet, this function does +nothing. + =back =head1 AUTHOR @@ -443,10 +475,10 @@ Marius Gavrilescu Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2014 by Marius Gavrilescu +Copyright (C) 2014-2015 by Marius Gavrilescu This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.18.1 or, +it under the same terms as Perl itself, either Perl version 5.20.1 or, at your option, any later version of Perl 5 you may have available.