$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);
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($_);
}