NAME

Gearman::Driver::Worker - Base class for workers

SYNOPSIS

package My::Worker;

use base qw(Gearman::Driver::Worker);
use Moose;

sub prefix {
    # default: return ref(shift) . '::';
    return join '_', split /::/, __PACKAGE__;
}

sub do_something : Job : MinChilds(2) : MaxChilds(15) {
    my ( $self, $job ) = @_;
    # $job => Gearman::XS::Job instance
}

1;

DESCRIPTION

METHODATTRIBUTES

Job

This will register the method with gearmand.

MinChilds

Minimum number of childs working parallel on this job/method.

MaxChilds

Maximum number of childs working parallel on this job/method.

METHODS

prefix

Having the same method name in two different classes would result in a clash when registering it with gearmand. To avoid this, all jobs are registered with the full package and method name (e.g. My::Worker::some_job). The default prefix is ref(shift . '::'), but this can be changed by overriding the prefix method in the subclass, see "SYNOPSIS" above.

begin

This method is called before a job method is called. In this base class this methods just does nothing, but can be overridden in a subclass.

The parameters are the same as in the job method:

  • $self

  • $job

end

This method is called after a job method has been called. In this base class this methods just does nothing, but can be overridden in a subclass.

The parameters are the same as in the job method:

  • $self

  • $job

AUTHOR

Johannes Plunien <plu@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2009 by Johannes Plunien

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

SEE ALSO