start
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 26 Sep 2011 16:06:07 +0000 (12:06 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 26 Sep 2011 23:31:54 +0000 (19:31 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/asterisk/pbx-daemon/eg-pbx-allocator.pl

index 10d0c17..7a1b3b9 100755 (executable)
@@ -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($_);
 }