#! perl -slw
use strict;
use threads;
use Thread::Queue;
use LWP::Simple;
{
package T::Q::O;
use Data::Dump qw[ pp ];
require Thread::Queue;
use threads;
use threads::shared;
our @ISA = 'Thread::Queue';
sub enqueue {
local $^W;
my $Q = shift;
lock @$Q;
for( @_ ) {
push @$Q, $_;
my $n = $#$Q;
@{ $Q }[ $n, $n-1 ] = @{ $Q }[ $n-1, $n ], --$n
while $n-1 and $Q->[ $n ] < $Q->[ $n - 1 ];
}
cond_signal( @$Q );
}
sub dump {
my $Q = shift;
lock @$Q;
pp $Q;
cond_signal( @$Q );
}
}
sub dbiFetch {
my @args = @_;
return getstore $args[ 0 ], 'nul';
}
sub sshFetch {
my @args = @_;
return getstore $args[ 0 ], 'nul';
}
sub tcpFetch {
my @args = @_;
return getstore $args[ 0 ], 'nul';
}
sub worker {
no strict 'refs';
my $Q = shift;
while( my $work = $Q->dequeue ) {
my( $time, $interval, $sub, @args ) = split $;, $work;
sleep 1 while time() < $time;
# printf "now: %.f time:$time int:$interval sub:$sub [@args]",
+time();
my $result = $sub->( @args );
# print $result;
$Q->enqueue( join $;, $time + $interval, $interval, $sub, @arg
+s );
}
}
our $W //= 10;
my $Q = new T::Q::O;
my @workers = map async( \&worker, $Q ), 1 .. $W;
while( <> ) {
chomp;
$Q->enqueue( join $;,
time(), (map $_*60, 1,2,3 )[ rand 3 ],
( qw[dbiFetch sshFetch tcpFetch ] )[ rand 3 ],
$_
);
}
1 while sleep 1;
-
-
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|