From 868735280ee7f1de62d9ede01cb0f4ad4efb51d0 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Mon, 26 Sep 2011 12:06:07 -0400 Subject: [PATCH] start Signed-off-by: Lebbeous Fogle-Weekley --- .../src/asterisk/pbx-daemon/eg-pbx-allocator.pl | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/asterisk/pbx-daemon/eg-pbx-allocator.pl b/Open-ILS/src/asterisk/pbx-daemon/eg-pbx-allocator.pl index 10d0c170f1..7a1b3b9e85 100755 --- a/Open-ILS/src/asterisk/pbx-daemon/eg-pbx-allocator.pl +++ b/Open-ILS/src/asterisk/pbx-daemon/eg-pbx-allocator.pl @@ -165,6 +165,17 @@ sub queue { $opts{v} and print $msg . "\n"; } +sub still_valid { + my ($filename) = @_; + # Here we want to contact Evergreen's open-ils.trigger service and get + # a revalidation of the event described in a given file. + # We'll return 1 for valid, 0 for invalid. + + print STDERR "filename is $filename\n"; # XXX + + return 1; +} + ### MAIN ### getopts('htvc:', \%opts) or pod2usage(2); @@ -197,26 +208,41 @@ my $out_count = scalar @outgoing; my $limit = $config{queue_limit} || 0; my $available = 0; +my @actually = (); + if ($limit) { $available = $limit - $out_count; - if ($in_count > $available) { - @incoming = @incoming[0..($available-1)]; # slice down to correct size - } if ($available == 0) { $opts{t} or syslog LOG_NOTICE, "Queue is full ($limit)"; } + + # Take as many files from @incoming as it takes to fill up @actually + # with files whose contents describe still-valid events. + for (my $i = 0; $i < $available; $i++) { + while (@incoming) { + my $candidate = shift @incoming; + if (still_valid($candidate)) { + unshift @actually, $candidate; + last; + } + } + } } +# XXX Even without a limit we should still filter by still_valid() in theory, +# but in practive the user should always use a limit. + if ($opts{v}) { - printf "incoming (total ): %3d\n", $raw_count; - printf "incoming (future): %3d\n", scalar @future; - printf "incoming (active): %3d\n", $in_count; - printf "queued already : %3d\n", $out_count; - printf "queue_limit : %3d\n", $limit; - printf "available spots : %3s\n", ($limit ? $available : 'unlimited'); + printf "incoming (total) : %3d\n", $raw_count; + printf "incoming (future) : %3d\n", scalar @future; + printf "incoming (active) : %3d\n", $in_count; + printf "incoming (filtered): %3d\n", scalar @actually; + printf "queued already : %3d\n", $out_count; + printf "queue_limit : %3d\n", $limit; + printf "available spots : %3s\n", ($limit ? $available : 'unlimited'); } -foreach (@incoming) { +foreach (@actually) { # $opts{v} and print `ls -l $_`; # ' ', (stat($_))[9], " - $now = ", (stat($_))[9] - $now, "\n"; queue($_); } -- 2.11.0