Devanchya has asked for the wisdom of the Perl Monks concerning the following question:
In what I hope is my final question on POE... and thus giving me enough information to finish this mini-project I ask the following:
I have the following structure, and I apologize for no code sample at the moment. This is an extension to my questions: http://perlmonks.org/?node_id=708535 and
I have a POE::Component::JobQueue which I get information off passively. This works great, it goes into the new session and is able to Trigger a POE::Wheel::Run which runs an application that takes about 45 minutes to complete.
The Issue is:
As soon as the new Session with the Wheel::Run in it is fired, the session returns to the JobQueue saying it is finished. This isn't true, it should only be returning finished once the ChildClosed event is done in the Wheel::Run
As is normal, I have searched Google and the POE Cookbooks and still scratch my head.
POE::Component::JobQueue->spawn ( Alias => 'MyQueue', WorkerLimit => $numOfWorkerThreads, Worker => \&make_a_worker, Passive => { }, ); # Code that creates a seperate Session # Snipped due to Vendor limits sub handle_message { $kernel->yield( enqueue_msg => $msg ); } exit 0; # This gets posted to sub enqueue_msg { my ($kernel, $session, $message) = @_[ KERNEL, SESSION, ARG0 ]; print "-enqueue_job: -- Session: ", $session->ID, " message\n"; $kernel->post( MyQueue => 'enqueue', 'finish_job', $message ); } sub make_a_worker { my ( $postback, $message ) = @_; my @results = create_worker_session( $message ); $postback->(@results); } ## Do the actual creation of the worker session sub create_worker_session { my $message = shift; POE::Session->create( inline_states => { _start => \&worker_start, worker_child_stdout => \&worker_child_stdout, worker_closed => \&worker_closed, sig_child => \&sig_child, }, args => [ '', $message ], ); return "Message ID: ".$message->getHeaderField('MessageID')." -- F +inished... \n"; } sub worker_start { my ($kernel, $session, $heap, @args ) = @_[KERNEL, SESSION, HEAP, +ARG0 .. $#_]; $heap->{MessageID} = $args[1]->getHeaderField('MessageID'); $heap->{SessionID} = $session->ID; print " Message ID: ".$heap->{MessageID}; print " -start_message_process: ".$heap->{SessionID}."\n"; my $fullCMD = "/my/long/running/command -i foobar"; $heap->{cmdlinefish} = POE::Wheel::Run->new( Program => $fullCMD, StdoutEvent => "worker_child_stdout", CloseEvent => "worker_closed", StdioFilter => POE::Filter::Reference->new(), ); print " Message ID: ".$heap->{MessageID}; print " -start_message_process (end): ".$heap->{SessionID}."\n"; } sub worker_child_stdout { my ( $heap, $preargs ) = @_[ HEAP, ARG0 ]; print " Message ID: ".$heap->{MessageID}; print " -worker_child_stdout: $preargs\n"; } sub worker_closed { my ( $kernel, $heap, $preargs ) = @_[ KERNEL, HEAP, ARG1 ]; print " Message ID: ".$heap->{MessageID}; print " -worker_closed: $preargs\n"; $kernel->yield('sig_child'); } sub sig_child { my ( $heap, $sig, $pid, $exit_val ) = @_[ HEAP, ARG0, ARG1, ARG2 ] +; my $details = delete $heap->{cmdlinefish}; print " Message ID: ".$heap->{MessageID}; print " -sig_child\n"; return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: POE, Sessons, POE::Wheel::Run and program flow
by themage (Friar) on Sep 04, 2008 at 17:22 UTC | |
by Devanchya (Beadle) on Sep 04, 2008 at 17:59 UTC | |
|
Re: POE, Sessons, POE::Wheel::Run and program flow
by rhesa (Vicar) on Sep 04, 2008 at 15:19 UTC | |
|
Re: POE, Sessons, POE::Wheel::Run and program flow
by themage (Friar) on Sep 04, 2008 at 15:14 UTC | |
|
Re: POE, Sessons, POE::Wheel::Run and program flow
by Devanchya (Beadle) on Sep 04, 2008 at 16:20 UTC |