1Gearman::Client(3)    User Contributed Perl Documentation   Gearman::Client(3)
2
3
4

NAME

6       Gearman::Client - Client for gearman distributed job system
7

SYNOPSIS

9           use Gearman::Client;
10           my $client = Gearman::Client->new;
11           $client->job_servers(
12             '127.0.0.1',
13             {
14               host      => '10.0.0.1',
15               port      => 4730,
16               socket_cb => sub {...},
17               use_ssl   => 1,
18               ca_file   => ...,
19               cert_file => ...,
20               key_file  => ...,
21             }
22           );
23
24           # running a single task
25           my $result_ref = $client->do_task("add", "1+2", {
26             on_fail => sub {...},
27             on_complete => sub {...}
28           });
29           print "1 + 2 = $$result_ref\n";
30
31           # waiting on a set of tasks in parallel
32           my $taskset = $client->new_task_set;
33           $taskset->add_task( "add" => "1+2", {
34              on_complete => sub { ... }
35           });
36           $taskset->add_task( "divide" => "5/0", {
37              on_fail => sub { print "divide by zero error!\n"; },
38           });
39           $taskset->wait;
40

DESCRIPTION

42       Gearman::Client is a client class for the Gearman distributed job
43       system, providing a framework for sending jobs to one or more Gearman
44       servers. These jobs are then distributed out to a farm of workers.
45
46       Callers instantiate a Gearman::Client object and from it dispatch
47       single tasks, sets of tasks, or check on the status of tasks.
48
49       Gearman::Client is derived from Gearman::Objects
50

USAGE

52   Gearman::Client->new(%options)
53       Creates a new Gearman::Client object, and returns the object.
54
55       If %options is provided, initializes the new client object with the
56       settings in %options, which can contain:
57
58       ·   exceptions
59
60           If true, the client sends an OPTION_REQ exceptions
61           <http://gearman.org/protocol/> request for each connection to the
62           job server.  This causes job server to forward WORK_EXCEPTION
63           packets to the client.
64
65       ·   job_servers
66
67           List of job servers. Value should be an array reference, hash
68           reference or scalar.
69
70           Calls Gearman::Objects to set job_servers
71
72       ·   prefix
73
74           Calls prefix (see Gearman::Objects) to set the prefix / namespace.
75
76       ·   command_timeout
77
78           Maximum time a gearman command should take to get a result (not a
79           job timeout)
80
81           default: 30 seconds
82
83       ·   backoff_max
84
85           Max number of failed connection attempts before an job server will
86           be temporary disabled
87
88           default: 90
89

EXAMPLES

91   Summation
92       This is an example client that sends off a request to sum up a list of
93       integers.
94
95           use Gearman::Client;
96           use Storable qw( freeze );
97           my $client = Gearman::Client->new;
98           $client->job_servers('127.0.0.1');
99           my $tasks = $client->new_task_set;
100           my $handle = $tasks->add_task(sum => freeze([ 3, 5 ]), {
101               on_complete => sub { print ${ $_[0] }, "\n" }
102           });
103           $tasks->wait;
104
105       See the Gearman::Worker documentation for the worker for the sum
106       function.
107

NOTE

109       If you intend using UTF-8 data with SSL based connection, beware there
110       is no UTF-8 support in underlying Net::SSLeay.
111       "Forcing-Unicode-in-Perl-(Or-Unforcing-Unicode-in-Perl)" in perlunicode
112       describes proper workarounds.
113

METHODS

115   new_task_set()
116       Creates and returns a new Gearman::Taskset object.
117
118   get_job_server_status()
119       return "{job_server => {job => {capable, queued, running}}}"
120
121   get_job_server_jobs()
122       supported only by Gearman::Server
123
124       return "{job-server => {job => {address, listeners, key}}}"
125
126   get_job_server_clients()
127       supported only by Gearman::Server
128
129   do_task($task)
130   do_task($funcname, $arg, \%options)
131       Dispatches a task and waits on the results.  May either provide a
132       Gearman::Task object, or the 3 arguments that the Gearman::Task
133       constructor takes.
134
135       return scalarref of WORK_COMPLETE result, or undef on failure.
136
137   dispatch_background($func, $arg_p, $options_hr)
138   dispatch_background($task)
139       Dispatches a "task" and doesn't wait for the result. Return value is an
140       opaque scalar that can be used to refer to the task with get_status.
141
142       It is strongly recommended to set Gearman::Task "uniq" option to insure
143       gearmand does not squash jobs if it store background jobs in a
144       persistence backend.  See the issue #87
145       <https://github.com/gearman/gearmand/issues/87#issuecomment-291119785>
146
147       return the handle from the jobserver, or undef on failure
148
149   run_hook($name)
150       run a hook callback if defined
151
152   add_hook($name, $cb)
153       add a hook
154
155   get_status($handle)
156       The Gearman Server will assign a scalar job handle when you request a
157       background job with dispatch_background. Save this scalar, and use it
158       later in order to request the status of this job.
159
160       return Gearman::JobStatus on success
161
163       Copyright 2006-2007 Six Apart, Ltd.
164
165       License granted to use/distribute under the same terms as Perl itself.
166

WARRANTY

168       This is free software. This comes with no warranty whatsoever.
169

AUTHORS

171        Brad Fitzpatrick (<brad at danga dot com>)
172        Jonathan Steinert (<hachi at cpan dot org>)
173        Alexei Pastuchov (<palik at cpan dot org>) co-maintainer
174

REPOSITORY

176       <https://github.com/p-alik/perl-Gearman.git>
177
178
179
180perl v5.28.1                      2018-08-24                Gearman::Client(3)
Impressum