| AnyEvent::Gearman::Client - Gearman client for AnyEvent application |
AnyEvent::Gearman::Client - Gearman client for AnyEvent application
use AnyEvent::Gearman::Client;
# create greaman client
my $gearman = AnyEvent::Gearman::Client->new(
job_servers => ['127.0.0.1', '192.168.0.1:123'],
);
# start job
$gearman->add_task(
$function => $workload,
on_complete => sub {
my $res = $_[1];
},
on_fail => sub {
# job failed
},
);
This is Gearman client module for AnyEvent applications.
the Gearman::Client::Async manpage, this module provides same functionality for the Danga::Socket manpage applications.
new(%options)Create gearman client object.
my $gearman = AnyEvent::Gearman::Client->new(
job_servers => ['127.0.0.1', '192.168.0.1:123'],
);
Available options are:
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.
Start new job and wait results in %callbacks
$gearman->add_task(
$function => $workload,
on_complete => sub {
my $result = $_[1],
},
on_fail => sub {
# job failled
},
);
$function is a worker function name, and $workload is a data that will be passed to worker.
%callbacks is set of callbacks called by job events. Available callbacks are:
Called when the job is completed. $result is some results data which is set by $job->complete($result) in worker.
Called when the job is failed. $reason is empty if its threw by worker. I don't know why but gearman spec say so. Considering to use on_warning below for some failing notify.
Called when $job->warning($warning) called in worker.
Called when $job->data($data) called in worker.
Called when $job->status($numerator, $denominator) called in worker
You should to set on_complete and on_fail at least.
Daisuke Murase <typester@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.
| AnyEvent::Gearman::Client - Gearman client for AnyEvent application |