.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "AnyEvent::Gearman::Client 3pm" .TH AnyEvent::Gearman::Client 3pm "2016-12-07" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" AnyEvent::Gearman::Client \- Gearman client for AnyEvent application .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use AnyEvent::Gearman::Client; \& \& # create greaman client \& my $gearman = AnyEvent::Gearman::Client\->new( \& job_servers => [\*(Aq127.0.0.1\*(Aq, \*(Aq192.168.0.1:123\*(Aq], \& ); \& \& # start job \& $gearman\->add_task( \& $function => $workload, \& on_complete => sub { \& my $res = $_[1]; \& }, \& on_fail => sub { \& # job failed \& }, \& ); \& \& # start background job \& $gearman\->add_task_bg( \& $function => $workload, \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is Gearman client module for AnyEvent applications. .SH "SEE ALSO" .IX Header "SEE ALSO" Gearman::Client::Async, this module provides same functionality for Danga::Socket applications. .SH "METHODS" .IX Header "METHODS" .SS "new(%options)" .IX Subsection "new(%options)" Create gearman client object. .PP .Vb 3 \& my $gearman = AnyEvent::Gearman::Client\->new( \& job_servers => [\*(Aq127.0.0.1\*(Aq, \*(Aq192.168.0.1:123\*(Aq], \& ); .Ve .PP Available options are: .IP "job_servers => 'ArrayRef'," 4 .IX Item "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. .Sp You should set at least one job_server. .IP "prefix => 'Str'," 4 .IX Item "prefix => 'Str'," Sets the namespace / prefix for the function names. This is useful for sharing job servers between different applications or different instances of the same application (different development sandboxes for example). .Sp The namespace is currently implemented as a simple tab separated concatenation of the prefix and the function name. .ie n .SS "add_task($function, $workload, %callbacks)" .el .SS "add_task($function, \f(CW$workload\fP, \f(CW%callbacks\fP)" .IX Subsection "add_task($function, $workload, %callbacks)" Start new job and wait results in \f(CW%callbacks\fR .PP .Vb 9 \& $gearman\->add_task( \& $function => $workload, \& on_complete => sub { \& my $result = $_[1], \& }, \& on_fail => sub { \& # job failled \& }, \& ); .Ve .PP \&\f(CW$function\fR is a worker function name, and \f(CW$workload\fR is a data that will be passed to worker. .PP \&\f(CW%callbacks\fR is set of callbacks called by job events. Available callbacks are: .ie n .IP "on_complete => $cb\->($self, $result)" 4 .el .IP "on_complete => \f(CW$cb\fR\->($self, \f(CW$result\fR)" 4 .IX Item "on_complete => $cb->($self, $result)" Called when the job is completed. \f(CW$result\fR is some results data which is set by \f(CW\*(C`$job\->complete($result)\*(C'\fR in worker. .ie n .IP "on_fail => $cb\->($self, $reason)" 4 .el .IP "on_fail => \f(CW$cb\fR\->($self, \f(CW$reason\fR)" 4 .IX Item "on_fail => $cb->($self, $reason)" Called when the job is failed. \f(CW$reason\fR is empty if its threw by worker. I don't know why but gearman spec say so. Considering to use \f(CW\*(C`on_warning\*(C'\fR below for some failing notify. .ie n .IP "on_warning => $cb\->($self, $warning)" 4 .el .IP "on_warning => \f(CW$cb\fR\->($self, \f(CW$warning\fR)" 4 .IX Item "on_warning => $cb->($self, $warning)" Called when \f(CW\*(C`$job\->warning($warning)\*(C'\fR called in worker. .ie n .IP "on_data => $cb\->($self, $data)" 4 .el .IP "on_data => \f(CW$cb\fR\->($self, \f(CW$data\fR)" 4 .IX Item "on_data => $cb->($self, $data)" Called when \f(CW\*(C`$job\->data($data)\*(C'\fR called in worker. .ie n .IP "on_status => $cb\->($self, $numerator, $denominator)" 4 .el .IP "on_status => \f(CW$cb\fR\->($self, \f(CW$numerator\fR, \f(CW$denominator\fR)" 4 .IX Item "on_status => $cb->($self, $numerator, $denominator)" Called when \f(CW\*(C`$job\->status($numerator, $denominator)\*(C'\fR called in worker .ie n .IP "on_created => $cb\->($self)" 4 .el .IP "on_created => \f(CW$cb\fR\->($self)" 4 .IX Item "on_created => $cb->($self)" Called when the servers reports that the task was created successfully. Updates the Task object with the server assigned \f(CW\*(C`job_handle\*(C'\fR. .PP You should to set \f(CW\*(C`on_complete\*(C'\fR and \f(CW\*(C`on_fail\*(C'\fR at least. .ie n .SS "add_task_bg($function, $workload, %callbacks)" .el .SS "add_task_bg($function, \f(CW$workload\fP, \f(CW%callbacks\fP)" .IX Subsection "add_task_bg($function, $workload, %callbacks)" Starts a new background job. The parameters are the same as add_task($function, \f(CW$workload\fR, \f(CW%callbacks\fR), but the only callback that is called is \f(CW\*(C`on_created\*(C'\fR. .PP .Vb 6 \& $gearman\->add_task_bg( \& $function => $workload, \& on_created => sub { \& my ($task) = @_; \& }, \& ); .Ve .SH "AUTHOR" .IX Header "AUTHOR" Daisuke Murase .PP Pedro Melo .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (c) 2009 by \s-1KAYAC\s0 Inc. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \&\s-1LICENSE\s0 file included with this module.