#!/usr/bin/perl
use warnings;
use strict;
use Data::Dump qw(dump);
use Getopt::Long;
use Gearman::Worker;
my $host = '10.60.0.244:4730';
my $function = 'test';
GetOptions(
'host' => \$host,
'function' => \$function,
) || die $!;
my $worker = Gearman::Worker->new;
$worker->job_servers( $host );
$worker->register_function( $function => sub {
my $job = $_[0];
my $arg = $_[0]->arg;
warn "# job ",dump($job);
});
warn "# worker ",dump($worker);
$worker->work while 1;
=for client
my $client = Gearman::Client->new;
$client->job_servers($host);
# running a single task
my $result_ref = $client->do_task("add", "1+2");
print "1 + 2 = $$result_ref\n";
# waiting on a set of tasks in parallel
my $taskset = $client->new_task_set;
$taskset->add_task( "add" => "1+2", {
on_complete => sub { ... }
});
$taskset->add_task( "divide" => "5/0", {
on_fail => sub { print "divide by zero error!\n"; },
});
$taskset->wait;
=cut