All pastes #1624327 Raw Edit

clueless

public text v1 · immutable
#1624327 ·published 2009-10-16 22:42 UTC
rendered paste body
use strict;use warnings;use POE;use MooseX::Declare;use Data::Dumper;class MyJob with POEx::WorkerPool::Role::Job{        # this method is executed across the process boundary	method init_job    {		#my $self = shift;        # Multi step jobs are supported and even reported on, so just keep         # enqueuing steps        $self->enqueue_step (        	[            	sub {										#return 1;					# do some work here				},        		[qw/1/]        	]    	);	}}class NeedsParallelJobExecution{	with 'POEx::Role::SessionInstantiation';    use aliased 'POEx::Role::Event';    use POEx::WorkerPool::Types(':all');    use POEx::WorkerPool::WorkerEvents(':all');	use POEx::Types(':all');    use POEx::WorkerPool;		use Data::Dumper;    has pool => (		 is => 'ro',		 isa => DoesWorkerPool,		 lazy_build => 1	);    method _build_pool { 		#my $self = shift;			print "Initialized POOL!";		return POEx::WorkerPool->new(			max_workers => 1,            job_classes => ['MyJob'], 			options => $self->options,		)	};    after _start is Event    {		#my $self = shift;		print "Start Event!\n";        for(my $i = 0; $i <= 5; $i++  )        {			# we get back the alias of the worker with which our job was             # enqueued            my $alias = $self->pool->enqueue_job(MyJob->new());			print "Inside Loop $i Alias: $alias\n";            # we can subscribe to all sorts of events that the worker            # generates but for the simple case, we just want to know our            # jobs are done            #            # See POEx::PubSub for more information			$self->call($alias, 'subscribe', event_name => +PXWP_JOB_START, event_handler => 'job_start');			$self->call($alias, 'subscribe', event_name => +PXWP_JOB_ENQUEUED, event_handler => 'job_enqueued');			$self->call($alias, 'subscribe', event_name => +PXWP_JOB_COMPLETE, event_handler => 'job_complete');        	$self->call($alias, 'subscribe', event_name => +PXWP_JOB_PROGRESS, event_handler => 'job_progress');						$self->call($alias, 'subscribe', event_name => +PXWP_JOB_FAILED, event_handler => 'job_failed');		    	}	};	method job_enqueued (SessionID :$worker_id, DoesJob :$job) is Event    {        print "Worker($worker_id) queued Job(${\$job->ID})\n";    }     method job_start (SessionID :$worker_id, DoesJob :$job) is Event    {	    print "Worker($worker_id) has started Job(${\$job->ID})\n";    }        method job_complete (SessionID :$worker_id, DoesJob :$job, Ref :$msg) is Event    {        print "Worker($worker_id) finished Job(${\$job->ID})\n";    }     method job_progress (SessionID :$worker_id, DoesJob :$job, Int :$percent_complete, Ref :$msg) is Event    {        print "Worker($worker_id) is %$percent_complete with Job(${\$job->ID})";    }		method job_failed (SessionID :$worker_id, DoesJob :$job, Ref :$msg) is Event    {        print "Job(${\$job->ID}) failed with: $$msg";    }}my $thing = NeedsParallelJobExecution->new();POE::Kernel->run();