PoCo::JobQueue skeleton
use POE qw( Session Component::JobQueue );
### The queue processing session
POE::Session->create(
inline_states => {
_start => \&start_queue,
acquire_jobs => \&acquire_jobs,
enqueue_job => \&enqueue_job,
finish_job => \&finish_job,
}
);
### The actual queue
POE::Component::JobQueue->spawn(
Alias => 'MyQueue',
WorkerLimit => 4,
Worker => sub {
my ( $postback, $job ) = @_;
my @results = process_job( $job );
$postback->(@results);
},
Passive => {},
);
# Main event loop
POE::Kernel->run();
# session states
sub start_queue
{
$_[KERNEL]->yield('acquire_jobs');
}
sub acquire_jobs
{
# implement some way to receive jobs.
# here i'm going to pretend i can poll some resource
# and loop indefinitely
if( my $job = poll_resource() ) {
$_[KERNEL]->yield( enqueue_job => $job );
}
# poll again in 10 seconds
$_[KERNEL]->delay_add( acquire_jobs => 10 );
}
sub enqueue_job
{
my ($job) = @_[ ARG0 ];
# this will enqueue the job on the job queue
$_[KERNEL]->post(
MyQueue => 'enqueue',
'finish_job', # our event on completion
$job
);
}
sub finish_job
{
my ( $request_packet, $response_packet ) = @_[ ARG0, ARG1 ];
my ($job) = @{$request_packet}; # original post/fetch
my @job_results = @{$response_packet}; # passed from the postba
+ck
# do cleanup
}
### example
our $p = 0;
sub poll_resource { ++$p }
sub process_job { my $job = shift; print "I got job $job\n" }
__END__
Programming hurdles
- assignment and sequence seem trivial, but trip up many;
- choice is not much of an additional hurdle;
- iteration / recursion is hard, and is the cliff at which the
remaining failures pause;
- concurrency is reached by only a tiny percentage of
programmers in their lifetime.
From "The elephant in the room",
Richard Bornat and Saeed Dehnadi,
School of Computing Science, Middlesex University
(presentation slides" (in PDF))
CPAN shell - list of issues/quirks/gripes
Someone asked me to keep a list of things that might be improved about the cpan shell. So I'm keeping that here.
- Documentation
- Context sensitive help. I'd love to do "help o conf" and be told how it works; esp. since the documentation is so scant on this
- Command line parsing: switching between ppm and cpan made me type "cpan install Foo" a lot, but "install" pulls in ponie plus a whole cart of manure
- How does o conf work with lists? Every time I have to tweak the mirror list, I get lost or screw up the list.
- It would be nice if the build process would halt at the first sign of trouble. Having to wade through pages of output to find the culprit is difficult, or even impossible.
- Dependency handling + build/test failures
- pure M::B dist support
|