From edfc5928b7d9ee441f2f0eaf9b3cadec58bbf947 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 19 Dec 2014 10:03:11 +0200 Subject: [PATCH] Add a purge sub and use it in gruntmaster-* --- gruntmaster-contest | 14 ++++++++++---- gruntmaster-job | 14 +++++++++++--- gruntmaster-problem | 10 ++++++++-- lib/Gruntmaster/Data.pm | 9 +++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/gruntmaster-contest b/gruntmaster-contest index 856faae..6b78104 100755 --- a/gruntmaster-contest +++ b/gruntmaster-contest @@ -33,17 +33,21 @@ END } sub cmd_add{ - my $id = shift; + my ($id) = @_; my $name = prompt 'Contest name'; my $owner = prompt 'Owner'; my $start = str2time prompt 'Start time' or die 'Cannot parse time'; my $stop = str2time prompt 'Stop time' or die 'Cannot parse time'; - $db->contests->create({id => $id, name => $name, owner => $owner, start => $start, stop => $stop}) + $db->contests->create({id => $id, name => $name, owner => $owner, start => $start, stop => $stop}); + purge '/ct/'; } sub cmd_rm{ - $db->contest(shift)->delete + my ($id) = @_; + $db->contest(shift)->delete; + purge '/ct/'; + purge "/ct/$id"; } sub cmd_get{ @@ -53,7 +57,9 @@ sub cmd_get{ sub cmd_set{ my ($id, %values) = @_; - $db->contest($id)->update(\%values) + $db->contest($id)->update(\%values); + purge '/ct/'; + purge "/ct/$id"; } ################################################## diff --git a/gruntmaster-job b/gruntmaster-job index 06e3fe1..47bb2ab 100755 --- a/gruntmaster-job +++ b/gruntmaster-job @@ -32,7 +32,10 @@ END } sub cmd_rm{ - $db->job(shift)->delete + my ($id) = @_; + $db->job($id)->delete; + purge '/log/'; + purge "/log/$id"; } sub cmd_get{ @@ -42,11 +45,16 @@ sub cmd_get{ sub cmd_set{ my ($id, %values) = @_; - $db->job($id)->update(\%values) + $db->job($id)->update(\%values); + purge '/log/'; + purge "/log/$id"; } sub cmd_rerun{ - $db->job(shift)->rerun + my ($id) = @_; + $db->job($id)->rerun; + purge '/log/'; + purge "/log/$id"; } ################################################## diff --git a/gruntmaster-problem b/gruntmaster-problem index 5d18b2b..dac2e02 100755 --- a/gruntmaster-problem +++ b/gruntmaster-problem @@ -88,6 +88,7 @@ sub cmd_add{ $db->problems->create (\%options); $db->contest_problems->create({problem => $id, contest => $contest}) if $contest; + purge '/pb/'; } sub cmd_set{ @@ -95,7 +96,9 @@ sub cmd_set{ GetOptions ( 'file!' => \$file ); my ($id, %values) = @_; %values = map { $_ => scalar read_file $values{$_} } keys %values if $file; - $db->problem($id)->update(\%values) + $db->problem($id)->update(\%values); + purge '/pb/'; + purge "/pb/$id"; } sub cmd_get{ @@ -109,7 +112,10 @@ sub cmd_list{ } sub cmd_rm{ - $db->problem(shift)->delete + my ($id) = @_; + $db->problem($id)->delete; + purge '/pb/'; + purge "/pb/$id"; } sub cmd_show{ diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 9d01418..e514970 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -15,10 +15,13 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-05 13:11:39 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dAEmtAexvUaNXLgYz2rNEg +use parent qw/Exporter/; our $VERSION = '5999.000_012'; +our @EXPORT = qw/purge/; use Lingua::EN::Inflect qw/PL_N/; use JSON::MaybeXS qw/decode_json/; +use HTTP::Tiny; use PerlX::Maybe qw/maybe/; use Sub::Name qw/subname/; @@ -180,6 +183,12 @@ sub update_status { $self->txn_do($txn); } +my @PURGE_HOSTS = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : (); +my $ht = HTTP::Tiny->new; + +sub purge { $ht->request(PURGE => "http://$_$_[0]") for @PURGE_HOSTS } + + 1; __END__ -- 2.39.2