|
NAMEAnyEvent::Gearman::Client - Gearman client for AnyEvent application SYNOPSIS 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
},
);
# start background job
$gearman->add_task_bg(
$function => $workload,
);
DESCRIPTIONThis is Gearman client module for AnyEvent applications. SEE ALSOGearman::Client::Async, this module provides same functionality for Danga::Socket applications. METHODSnew(%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:
add_task($function, $workload, %callbacks)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:
You should to set "on_complete" and "on_fail" at least. add_task_bg($function, $workload, %callbacks)Starts a new background job. The parameters are the same as add_task($function, $workload, %callbacks), but the only callback that is called is "on_created". $gearman->add_task_bg(
$function => $workload,
on_created => sub {
my ($task) = @_;
},
);
AUTHORDaisuke Murase <typester@cpan.org> Pedro Melo <melo@cpan.org> COPYRIGHT AND LICENSECopyright (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.
|