1MooseX::Workers(3) User Contributed Perl Documentation MooseX::Workers(3)
2
3
4
6 MooseX::Workers - Provides a simple sub-process management for
7 asynchronous tasks.
8
10 This document describes MooseX::Workers version 0.0.1
11
13 package Manager;
14 use Moose;
15 with qw(MooseX::Workers);
16
17 sub run {
18 $_[0]->spawn( sub { sleep 3; print "Hello World\n" } );
19 warn "Running now ... ";
20 POE::Kernel->run();
21 }
22
23 # Implement our Interface
24 sub worker_manager_start { warn 'started worker manager' }
25 sub worker_manager_stop { warn 'stopped worker manager' }
26 sub max_workers_reached { warn 'maximum worker count reached' }
27
28 sub worker_stdout { shift; warn join ' ', @_; }
29 sub worker_stderr { shift; warn join ' ', @_; }
30 sub worker_error { shift; warn join ' ', @_; }
31 sub worker_done { shift; warn join ' ', @_; }
32 sub worker_started { shift; warn join ' ', @_; }
33 sub sig_child { shift; warn join ' ', @_; }
34 no Moose;
35
36 Manager->new->run();
37
39 MooseX::Workers is a Role that provides easy delegation of long-running
40 tasks into a managed child process. Process managment is taken care of
41 via POE and it's POE::Wheel::Run module.
42
44 spawn ($command) =item fork ($command) =item run_command ($command)
45 This is the whole point of this module. This will pass $command
46 through to the MooseX::Worker::Engine which will take care of
47 running this asynchronously.
48
49 check_worker_threshold
50 This will check to see how many workers you have compared to the
51 max_workers limit. It returns true if the $num_workers is >=
52 $max_workers;
53
54 max_workers($count)
55 An accessor for the maxium number of workers. This is delegated to
56 the MooseX::Workers::Engine object.
57
58 has_workers
59 Check to see if we have *any* workers currently. This is delegated
60 to the MooseX::Workers::Engine object.
61
62 num_workers
63 Return the current number of workers. This is delegated to the
64 MooseX::Workers::Engine object.
65
66 meta
67 The Metaclass for MooseX::Workers::Engine see Moose's
68 documentation.
69
71 MooseX::Worker::Engine supports the following callbacks:
72
73 worker_manager_start
74 Called when the managing session is started
75
76 worker_manager_stop
77 Called when the managing session stops
78
79 max_workers_reached
80 Called when we reach the maximum number of workers
81
82 worker_stdout
83 Called when a child prints to STDOUT
84
85 worker_stderr
86 Called when a child prints to STDERR
87
88 worker_error
89 Called when there is an error condition detected with the child.
90
91 worker_done
92 Called when a worker completes $command
93
94 worker_started
95 Called when a worker starts $command
96
97 sig_child
98 Called when the mangaging session recieves a SIG CHDL event
99
100 See MooseX::Workers::Engine for more details.
101
103 MooseX::Workers requires no configuration files or environment
104 variables.
105
107 Moose, POE, POE::Wheel::Run
108
110 None reported.
111
113 No bugs have been reported.
114
115 Please report any bugs or feature requests to
116 "bug-moosex-workers@rt.cpan.org", or through the web interface at
117 <http://rt.cpan.org>.
118
120 Chris Prather "<perigrin@cpan.org>"
121
122 Tom Lanyon "<dec@cpan.org>"
123
125 Copyright (c) 2007, Chris Prather "<perigrin@cpan.org>". Some rights
126 reserved.
127
128 This module is free software; you can redistribute it and/or modify it
129 under the same terms as Perl itself. See perlartistic.
130
132 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
133 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
134 WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
135 PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
136 EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
137 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
138 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
139 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
140 NECESSARY SERVICING, REPAIR, OR CORRECTION.
141
142 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
143 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
144 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
145 TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
146 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
147 SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
148 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
149 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
150 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
151 DAMAGES.
152
153
154
155perl v5.12.0 2009-04-27 MooseX::Workers(3)