Add features to gen_site.pl manager through socket communication: freeze/unfreeze, ls and show

This commit is contained in:
nemunaire 2015-01-14 15:45:06 +01:00 committed by Nemunaire
parent d422fe8b64
commit 555cf56bfe

View File

@ -10,7 +10,7 @@
#
#=============================================================================
use v5.10.1;
use v5.12;
use strict;
use warnings;
use threads;
@ -136,6 +136,25 @@ sub manage
for ($cmd)
{
if (/^freeze/)
{
my $dq;
{
lock($queue);
$dq = $queue->dequeue();
if ($dq ne $cmd) {
$queue->insert(0, $dq);
$cmd = $dq;
}
}
if ($dq eq $cmd)
{
lock($queue);
cond_wait($queue) while $queue->pending() <= 0 || $queue->peek() !~ /^unfreeze/;
last;
}
}
if (/^all$/)
{
say "Generate all teams";
@ -306,13 +325,40 @@ sub parse($$;$)
for my $cmd ($cmds =~ /([^:]+)/g)
{
my $len = length($cmd);
# Search the right position
my $i;
for ($i = 0; $i < $queue->pending(); $i++)
if ($cmd =~ "^(un)?freeze")
{
last if ($len > length($queue->peek($i)));
$i = 0;
}
elsif ($cmd =~ "^show")
{
lock($queue);
say $chan_output "Pending queue:";
for ($i = 0; $i < $queue->pending(); $i++) {
say $chan_output "$i. $queue->peek($i)";
}
say $chan_output "empty!" if $queue->pending() == 0;
next;
}
elsif ($cmd =~ "^ls")
{
say $chan_output "Content of $main::tmpdir:";
opendir(my $dh, $main::tmpdir) || next;
while (readdir $dh) {
say $chan_output "$_";
}
closedir $dh;
next;
}
else
{
my $len = length($cmd);
# Search the right position
for ($i = 0; $i < $queue->pending(); $i++)
{
last if ($len > length($queue->peek($i)));
}
}
say $chan_output "Inserting $cmd at position $i/".$queue->pending();
$queue->insert($i, $cmd);
@ -371,6 +417,8 @@ sub socket_run
{
chomp $_;
parse($m, $_, $connection);
print $connection "\n";
$connection->flush;
}
say "Closing socket connection; stopping thread.";
close $connection;
@ -872,6 +920,10 @@ Number of parallel fetch to perform.
=over
=item B<freeze>
Freeze the scheduler until unfreeze is sent.
=item B<all>
Generate pages for all teams.