1Gearman::Client(3) User Contributed Perl Documentation Gearman::Client(3)
2
3
4
6 Gearman::Client - Client for gearman distributed job system
7
9 use Gearman::Client;
10 my $client = Gearman::Client->new;
11 $client->job_servers('127.0.0.1', '10.0.0.1');
12
13 # running a single task
14 my $result_ref = $client->do_task("add", "1+2");
15 print "1 + 2 = $$result_ref\n";
16
17 # waiting on a set of tasks in parallel
18 my $taskset = $client->new_task_set;
19 $taskset->add_task( "add" => "1+2", {
20 on_complete => sub { ... }
21 });
22 $taskset->add_task( "divide" => "5/0", {
23 on_fail => sub { print "divide by zero error!\n"; },
24 });
25 $taskset->wait;
26
28 Gearman::Client is a client class for the Gearman distributed job sys‐
29 tem, providing a framework for sending jobs to one or more Gearman
30 servers. These jobs are then distributed out to a farm of workers.
31
32 Callers instantiate a Gearman::Client object and from it dispatch sin‐
33 gle tasks, sets of tasks, or check on the status of tasks.
34
36 Gearman::Client->new(%options)
37
38 Creates a new Gearman::Client object, and returns the object.
39
40 If %options is provided, initializes the new client object with the
41 settings in %options, which can contain:
42
43 * job_servers
44 Calls job_servers (see below) to initialize the list of job
45 servers. Value in this case should be an arrayref.
46
47 * prefix
48 Calls prefix (see below) to set the prefix / namespace.
49
50 $client->job_servers(@servers)
51
52 Initializes the client $client with the list of job servers in
53 @servers. @servers should contain a list of IP addresses, with
54 optional port numbers. For example:
55
56 $client->job_servers('127.0.0.1', '192.168.1.100:7003');
57
58 If the port number is not provided, 7003 is used as the default.
59
60 $client->do_task($task)
61
62 $client->do_task($funcname, $arg, \%options)
63
64 Dispatches a task and waits on the results. May either provide a Gear‐
65 man::Task object, or the 3 arguments that the Gearman::Task constructor
66 takes.
67
68 Returns a scalar reference to the result, or undef on failure.
69
70 If you provide on_complete and on_fail handlers, they're ignored, as
71 this function currently overrides them.
72
73 $client->dispatch_background($task)
74
75 $client->dispatch_background($funcname, $arg, \%options)
76
77 Dispatches a task and doesn't wait for the result. Return value is an
78 opaque scalar that can be used to refer to the task.
79
80 $taskset = $client->new_task_set
81
82 Creates and returns a new Gearman::Taskset object.
83
84 $taskset->add_task($task)
85
86 $taskset->add_task($funcname, $arg, $uniq)
87
88 $taskset->add_task($funcname, $arg, \%options)
89
90 Adds a task to a taskset. Three different calling conventions are
91 available.
92
93 $taskset->wait
94
95 Waits for a response from the job server for any of the tasks listed in
96 the taskset. Will call the on_* handlers for each of the tasks that
97 have been completed, updated, etc. Doesn't return until everything has
98 finished running or failing.
99
100 $client->prefix($prefix)
101
102 Sets the namespace / prefix for the function names.
103
104 See Gearman::Worker for more details.
105
107 Summation
108
109 This is an example client that sends off a request to sum up a list of
110 integers.
111
112 use Gearman::Client;
113 use Storable qw( freeze );
114 my $client = Gearman::Client->new;
115 $client->job_servers('127.0.0.1');
116 my $tasks = $client->new_task_set;
117 my $handle = $tasks->add_task(sum => freeze([ 3, 5 ]), {
118 on_complete => sub { print ${ $_[0] }, "\n" }
119 });
120 $tasks->wait;
121
122 See the Gearman::Worker documentation for the worker for the sum func‐
123 tion.
124
126 Copyright 2006-2007 Six Apart, Ltd.
127
128 License granted to use/distribute under the same terms as Perl itself.
129
131 This is free software. This comes with no warranty whatsoever.
132
134 Brad Fitzpatrick (brad@danga.com)
135 Jonathan Steinert (hachi@cpan.org)
136
137
138
139perl v5.8.8 2007-05-04 Gearman::Client(3)