GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AnyEvent::Gearman::Worker(3) User Contributed Perl Documentation AnyEvent::Gearman::Worker(3)

AnyEvent::Gearman::Worker - Gearman worker for AnyEvent application

    use AnyEvent::Gearman::Worker;
    
    # create gearman worker
    my $worker = AnyEvent::Gearman::Worker->new(
        job_servers => ['127.0.0.1', '192.168.0.1:123'],
    );
    
    # add worker function
    $worker->register_function( reverse => sub {
        my $job = shift;
        my $res = reverse $job->workload;
        $job->complete($res);
    });

This is Gearman worker module for AnyEvent applications.

Create gearman worker object.

    my $worker = AnyEvent::Gearman::Worker->new(
        job_servers => ['127.0.0.1', '192.168.0.1:123'],
    );

Options are:

job_servers => 'ArrayRef'
List of gearman servers. 'host:port' or just 'host' formats are allowed. In latter case, gearman default port 4730 will be used.

You should set at least one job_server.

Register worker function.

    $worker->register_function( reverse => sub {
        my $job = shift;
        my $res = reverse $job->workload;
        $job->complete($res);
    });

$function_name is function name string to register.

$subref is worker CodeRef that will be executed when the worker received a request for this function. And it will be passed a AnyEvent::Gearman::Job object representing the job that has been received by the worker.

NOTE: Unlike Gearman::Worker, this module ignore $subref's return value. So you should call either "$job->complete" or "$job->fail" at least.

This is because this module stands AnyEvent's asynchronous way, and this way more flexible in AnyEvent world.

For example:

    $worker->register_function( reverse => sub {
        my $job = shift;

        my $t; $t = AnyEvent->timer(
            after => 10,
            cb    => sub {
                undef $t;
                $job->complete('done!');
            },
        );
    });

This is simplest and meaningless codes but you can write worker process with AnyEvent way. This is asynchronous worker.

Unregister worker function, notifying to server that this worker no longer handle $function_name.

Daisuke Murase <typester@cpan.org>

Pedro Melo <melo@cpan.org>

Copyright (c) 2009 by KAYAC Inc.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

2013-02-05 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.