From: Marius Gavrilescu Date: Wed, 15 Jan 2014 09:01:14 +0000 (+0200) Subject: Add gruntmaster-paged X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=2264274695c1eb576c3c57dcce0bcc97a240a57a;p=gruntmaster-page.git Add gruntmaster-paged --- diff --git a/Makefile.PL b/Makefile.PL index 9c22e69..822a1c7 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,7 +4,7 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Gruntmaster::Page', VERSION_FROM => 'lib/Gruntmaster/Page.pm', - EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-problem/ ], + EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-problem/ ], ABSTRACT_FROM => 'lib/Gruntmaster/Page.pm', AUTHOR => 'Marius Gavrilescu ', MIN_PERL_VERSION => '5.14.0', diff --git a/gruntmaster-paged b/gruntmaster-paged new file mode 100755 index 0000000..ef2bf81 --- /dev/null +++ b/gruntmaster-paged @@ -0,0 +1,11 @@ +#!/usr/bin/perl -w +use v5.14; + +use Gruntmaster::Data qw/SUBSCRIBE WAIT_FOR_MESSAGES/; +use Gruntmaster::Page qw/_generate/; + +SUBSCRIBE 'genpage', \&_generate; +WAIT_FOR_MESSAGES 86400 while 1; + +1; +__END__ diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 9f4cf95..e2ef0dc 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -9,6 +9,7 @@ use Redis; our $contest; my $redis = Redis->new; +my $pubsub = Redis->new; sub dynsub{ no strict 'refs'; @@ -19,6 +20,10 @@ BEGIN { for my $cmd (qw/multi exec smembers get hget hset sadd srem incr hmset hsetnx/) { dynsub uc $cmd, sub { say "Arguments to \U$cmd: ", join ', ', @_; $redis->$cmd(@_) }; } + + for my $cmd (qw/publish subscribe wait_for_messages/) { + dynsub uc $cmd, sub { say "Arguments to \U$cmd: ", join ', ', @_; $pubsub->$cmd(@_) }; + } } sub cp { defined $contest ? "contest.$contest." : '' } diff --git a/lib/Gruntmaster/Page.pm b/lib/Gruntmaster/Page.pm index bce618c..9fad273 100644 --- a/lib/Gruntmaster/Page.pm +++ b/lib/Gruntmaster/Page.pm @@ -4,13 +4,14 @@ use 5.014000; use strict; use warnings; use parent qw/Exporter/; -our @EXPORT_OK = qw/generate/; +our @EXPORT_OK = qw/generate _generate/; use Fcntl qw/:flock/; use File::Basename qw/fileparse/; use File::Slurp qw/write_file/; use IO::Compress::Gzip qw/gzip/; use IO::File; +use Gruntmaster::Data qw/PUBLISH/; our $VERSION = '0.001'; our @generators; @@ -44,7 +45,7 @@ sub declaregen{ declaregen 'Pb::Entry' => qr,^${contest}pb/$component$,; } -sub generate{ +sub _generate{ my ($path) = @_; my ($path_noext, $ext) = $path =~ m/^(.*)\.(.*)$/; my $basename = fileparse $path_noext; @@ -74,6 +75,10 @@ sub generate{ close $typemap; } +sub generate{ + PUBLISH 'genpage', shift; +} + 1; __END__ # Below is stub documentation for your module. You'd better edit it!