AnyEvent::Gearman::Client
Gearman client for AnyEvent application
- Provided by: libanyevent-gearman-perl (Version: 0.10-2)
- Report a bug
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
},
);
# start background job
$gearman->add_task_bg(
$function => $workload,
);
This is Gearman client module for AnyEvent applications.
Gearman::Client::Async, this module provides same functionality for Danga::Socket applications.
Create gearman client object.
my $gearman = AnyEvent::Gearman::Client->new(
job_servers => ['127.0.0.1', '192.168.0.1:123'],
);
Available options are:
You should set at least one job_server.
The namespace is currently implemented as a simple tab separated concatenation of the prefix and the function name.
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.
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) = @_;
},
);
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.