/[sysadmin-cookbook]/recepies/gearman/gearman.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /recepies/gearman/gearman.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 203 - (show annotations)
Sat May 1 12:49:20 2010 UTC (10 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 931 byte(s)
simple perl command-line client depenent only on libgearman-client-perl which is in etch

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7 use Getopt::Long;
8 use Gearman::Worker;
9
10 my $host = '10.60.0.244:4730';
11 my $function = 'test';
12
13 GetOptions(
14 'host' => \$host,
15 'function' => \$function,
16 ) || die $!;
17
18
19 my $worker = Gearman::Worker->new;
20 $worker->job_servers( $host );
21 $worker->register_function( $function => sub {
22 my $job = $_[0];
23 my $arg = $_[0]->arg;
24 warn "# job ",dump($job);
25 });
26 warn "# worker ",dump($worker);
27 $worker->work while 1;
28
29 =for client
30
31 my $client = Gearman::Client->new;
32 $client->job_servers($host);
33
34 # running a single task
35 my $result_ref = $client->do_task("add", "1+2");
36 print "1 + 2 = $$result_ref\n";
37
38 # waiting on a set of tasks in parallel
39 my $taskset = $client->new_task_set;
40 $taskset->add_task( "add" => "1+2", {
41 on_complete => sub { ... }
42 });
43
44 $taskset->add_task( "divide" => "5/0", {
45 on_fail => sub { print "divide by zero error!\n"; },
46 });
47 $taskset->wait;
48
49 =cut

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26