GearmanX::Worker - Working class for the Gearmand job server
#-- define a class for your workers: package MyWorker; use base qw(GearmanX::Worker); sub echo :Expose { my $param = shift; # ... compute something return $result; } 1; #-- in the meantime in the worker server my $w = new MyWorker; $w->run_as_thread; #-- or alternatively $w->run; # block here # somewhere else in a gearman client use GearmanX::Client; my $c = new GearmanX::Client; my $r = $c->job ('echo', '1+2');
This class implements the necessary infrastructure to comfortably write a gearman (http://www.gearman.org/) server. Instead of messing around with a task object where you get your arguments, you simply derive a subclass of GearmanX::Worker and define some methods (subs actually) which can handle certain gearman jobs. For that you mark these methods with an attribute Expose.
Expose
Every job handler receives exactly one parameter. That can be a scalar, a list reference or a hash reference. This is the data sent from the client, which may use GearmanX::Client.
Every job handler is supposed to return a result. That should be a scalar, a list reference or a hash reference. This data will be sent back to the client.
As the gearman system only allows strings to be passed between clients and workers, there is a special encoding for list and hash references. See the implementation for details.
The constructor expects the following fields:
SERVERS
127.0.0.1
This field controls where the jobs servers are.
With this attribute you signal to the constructor that you intent a certain method to be exposed to the gearman systems as a job handler. At constructor time of your worker this method will be registered with the gearman server.
This starts the worker and blocks there. This method will never terminate. Well, unless the world explodes.
This method launches a thread and detaches it. It will not block and returns the thread object.
Robert Barta, <rho at devc.at>
<rho at devc.at>
Please report any bugs or feature requests to bug-gearmanx-worker at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=GearmanX-Worker. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-gearmanx-worker at rt.cpan.org
Copyright 2009 Robert Barta, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install GearmanX::Worker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GearmanX::Worker
CPAN shell
perl -MCPAN -e shell install GearmanX::Worker
For more information on module installation, please visit the detailed CPAN module installation guide.