Robert Barta > GearmanX-Worker > GearmanX::Worker

Download:
GearmanX-Worker-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

GearmanX::Worker - Working class for the Gearmand job server

SYNOPSIS ^

    #-- 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');

DESCRIPTION ^

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.

Parameter Handling

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.

Result Handling

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.

Owning the Protocol

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.

INTERFACE ^

Constructor

The constructor expects the following fields:

SERVERS (optional, default: 127.0.0.1)

This field controls where the jobs servers are.

Attributes

Expose

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.

Methods

run

This starts the worker and blocks there. This method will never terminate. Well, unless the world explodes.

run_as_thread

This method launches a thread and detaches it. It will not block and returns the thread object.

AUTHOR ^

Robert Barta, <rho at devc.at>

BUGS ^

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.

COPYRIGHT & LICENSE ^

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.

syntax highlighting: