From 555cf56bfe7aaff922baf56e3dc5c0ee277b74b3 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Wed, 14 Jan 2015 15:45:06 +0100 Subject: [PATCH] Add features to gen_site.pl manager through socket communication: freeze/unfreeze, ls and show --- gen_site.pl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/gen_site.pl b/gen_site.pl index f037958b..7d4f1b38 100755 --- a/gen_site.pl +++ b/gen_site.pl @@ -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 the scheduler until unfreeze is sent. + =item B Generate pages for all teams.