POEx::WorkerPool::Role::WorkerPool::OpenEndedWorker - A role that provides common semantics for open ended Workers
version 1.101610
# Put this use statement prior to any invocations of WorkerPool # See MooseX::CompileTime::Traits for more details use POEx::WorkerPool::Worker traits => ['POEx::WorkerPool::Role::WorkerPool::OpenEndedWorker'];
The default Worker role provides a great amount of control for set runs of jobs allowing all sorts of statistics to be captured of failed vs. completed jobs, etc. But sometimes, all of that functionality isn't needed when a dumb worker will fit the bill much better. That is what this role provides. It ignores the queue limits, job worker status, and is a truly opened ended worker. It will spin up as soon as _start is called and periodically check the queue for jobs. It will exhaust the queue each check provided it hasn't been halted or told to stop_processing.
is: rw, isa: Bool, default: 0
stop_processing is a flag used to stop periodic processing of the queue
is: ro, isa: Int, default: 1
process_queue_interval defines the interval for queue processing. This value is passed directly to POEs "delay_add" in POE::Kernel method.
is: ro, isa: HashRef[DoesJob], traits: Hash
This is the in process store of jobs for the open ended worker. Jobs are placed into this structure prior to being passed to the Guts component
The following handles are provided:
{ _get_in_process => 'get', _add_in_process => 'set', _del_in_process => 'delete', }
(DoesJob $job)
enqueue_job is advised to bypass the queue checks to allow an open ended worker queue.
This method fires +PXWP_JOB_ENQUEUED to the associated PubSub component on success.
Subscribers will need to have the following signature:
method handler (SessionID :$worker_id, DoesJob $job ) is Event
(ArrayRef[DoesJob] $jobs)
enqueue_jobs does the same thing as enqueue_job, but it acts on an array of jobs. Each job successfully enqueued means the worker will fire the +PXWP_JOB_ENQUEUED event via PubSub.
is Event
halt is advised to stop periodic processing
_start is advised to start the prcessing queue using the "process_queue_interval"
(JobStatus $job_status) is Event
This is the StdoutEvent for the child POE::Wheel::Run. It handles all of the child output which is in the form of JobStatus hashrefs. The following describes the potential events from the child and the actions taken
+PXWP_JOB_COMPLETE
Action: _in_process is cleared. PubSub Event: +PXWP_JOB_COMPLETE PubSub Signature: method handler(SessionID :$worker_id, DoesJob :$job, Ref :$msg) Notes: The :$msg argument will contain the output from the Job's execution
+PXWP_JOB_PROGRESS
Action: PubSub event posted. PubSub Event: +PXWP_JOB_PROGRESS PubSub Signature: method handler ( SessionID :$worker_id, DoesJob :$job, Int :$percent_complete, Ref :$msg, ) Notes: The :$msg argument will contain the output from the last step executed for multi-step jobs
+PXWP_JOB_FAILED
Action: _in_process is cleared. PubSub Event: +PXWP_JOB_FAILED PubSub Signature: method handler(SessionID :$worker_id, DoesJob :$job, Ref :$msg) Notes: The :$msg argument will contain the exception generated from the Job
+PXWP_JOB_START
Action: PubSub event posted. PubSub Event: +PXWP_JOB_START PubSub Signature: method handler ( SessionID :$worker_id, DoesJob :$job, ) Notes: This is an indication that the child process received the Job and is beginning execution.
This private event is the queue processor. As jobs are dequeued for processing, +PXWP_JOB_DEQUEUED will be fired via PubSub. Subscribers will need the following signature:
method handler(SessionID :$worker_id, DoesJob :$job) is Event
Once this method is called, it will exhaust the current queue and set itself up to be called again on an interval of one second. The interval is configurable via the "process_queue_interval"
(DoesJob $job) is Event
This private event is advised to store the in-process jobs into a separate data structure (since multiple are in flight at once) before being processed. If the child process doesn't exist for whatever reason, +PXWP_WORKER_INTERNAL_ERROR will be fired via PubSub. Subscribers need the following signature:
method handler(SessionID :$worker_id, Ref :$msg)
In process jobs can be accessed by ID in the "_in_process_jobs" attribute.
Nicholas R. Perez <nperez@cpan.org>
This software is copyright (c) 2010 by Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install POEx::WorkerPool, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POEx::WorkerPool
CPAN shell
perl -MCPAN -e shell install POEx::WorkerPool
For more information on module installation, please visit the detailed CPAN module installation guide.