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

NAME

6       Beanstalk::Client - Client class to talk to beanstalkd server
7

SYNOPSIS

9         use Beanstalk::Client;
10
11         my $client = Beanstalk::Client->new(
12           { server       => "localhost",
13             default_tube => 'mine',
14           }
15         );
16
17         # Send a job with explicit data
18         my $job = $client->put(
19           { data     => "data",
20             priority => 100,
21             ttr      => 120,
22             delay    => 5,
23           }
24         );
25
26         # Send job, data created by encoding @args. By default with YAML
27         my $job2 = $client->put(
28           { priority => 100,
29             ttr      => 120,
30             delay    => 5,
31           },
32           @args
33         );
34
35         # Send job, data created by encoding @args with JSON
36         use JSON::XS;
37         $client->encoder(sub { encode_json(\@_) });
38         my $job2 = $client->put(
39           { priority => 100,
40             ttr      => 120,
41             delay    => 5,
42           },
43           @args
44         );
45
46         # fetch a job
47         my $job3 = $client->reserve;
48

DESCRIPTION

50       Beanstalk::Client provides a Perl API of protocol version 1.0 to the
51       beanstalkd server, a fast, general-purpose, in-memory workqueue service
52       by Keith Rarick.
53

METHODS

55   Constructor
56       new ($options)
57           The constructor accepts a single argument, which is a reference to
58           a hash containing options.  The options can be any of the accessor
59           methods listed below.
60
61   Accessor Methods
62       server ([$hostname])
63           Get/set the hostname, and port, to connect to. The port, which
64           defaults to 11300, can be specified by appending it to the hostname
65           with a ":" (eg "localhost:1234").  (Default: "localhost:11300")
66
67       socket
68           Get the socket connection to the server.
69
70       delay ([$delay])
71           Set/get a default value, in seconds, for job delay. A job with a
72           delay will be placed into a delayed state and will not be placed
73           into the ready queue until the time period has passed.  This value
74           will be used by "put" and "release" as a default. (Default: 0)
75
76       ttr ([$ttr])
77           Set/get a default value, in seconds, for job ttr (time to run).
78           This value will be used by "put" as a default. (Default: 120)
79
80       priority ([$priority])
81           Set/get a default value for job priority. The highest priority job
82           is the job where the priority value is the lowest (ie jobs with a
83           lower priority value are run first). This value will be used by
84           "put", "release" and "bury" as a default. (Default: 10000)
85
86       encoder ([$encoder])
87           Set/get serialization encoder. $encoder is a reference to a
88           subroutine that will be called when arguments to "put" need to be
89           encoded to send to the beanstalkd server. The subroutine should
90           accept a list of arguments and return a string representation to
91           pass to the server. (Default: YAML::Syck::Dump)
92
93       decoder ([$decoder])
94           Set/get the serialization decoder. $decoder is a reference to a
95           subroutine that will be called when data from the beanstalkd server
96           needs to be decoded. The subroutine will be passed the data fetched
97           from the beanstalkd server and should return a list of values the
98           application can use.  (Default: YAML::Syck::Load)
99
100       error
101           Fetch the last error that happened.
102
103       connect_timeout ([$timeout])
104           Get/set timeout, in seconds, to use for the connect to the server.
105
106       default_tube ([$tube])
107           Set/get the name of a default tube to put jobs into and fetch from.
108
109           By default a connection to a beanstalkd server will put into the
110           "default" queue and also watch the "default" queue. If
111           "default_tube" is set when "connect" is called the connection will
112           be initialized so that "put" will put into the given tube and
113           "reserve" will fetch jobs from the given tube.  (Default: none)
114
115       debug ([$debug])
116           Set/get debug value. If set to a true value then all communication
117           with the server will be output with "warn"
118
119   Producer Methods
120       These methods are used by clients that are placing work into the queue
121
122       put ($options [, @args])
123           Insert job into the currently used tube. Options may be
124
125           priority
126               priority to use to queue the job.  Jobs with smaller priority
127               values will be scheduled before jobs with larger priorities.
128               The most urgent priority is 0
129
130               Defaults to "$self-"priority>
131
132           delay
133               An integer number of seconds to wait before putting the job in
134                  the ready queue. The job will be in the "delayed" state
135               during this time
136
137               Defaults to "$self-"delay>
138
139           ttr "time to run" - An integer number of seconds to allow a worker
140               to run this job. This time is counted from the moment a worker
141               reserves this job. If the worker does not delete, release, or
142               bury the job within "ttr" seconds, the job will time out and
143               the server will release the job.  The minimum ttr is 1. If the
144               client sends 0, the server will silently increase the ttr to 1.
145
146           data
147               The job body. Defaults to the result of calling the current
148               encoder passing @args
149
150       use ($tube)
151           Change tube that new jobs are inserted into
152
153   Worker Methods
154       reserve ([$timeout])
155           Reserve a job from the list of tubes currently being watched.
156
157           Returns a Beanstalk::Job on success. $timeout is the maximum number
158           of seconds to wait for a job to become ready. If $timeout is not
159           given then the client will wait indefinitely.
160
161           Returns undef on error or if $timeout expires.
162
163       delete ($id)
164           Delete the specified job.
165
166       release ($id, [, $options])
167           Release the specified job. Valid options are
168
169           priority
170               New priority to assign to the job
171
172           delay
173               An integer number of seconds to wait before putting the job in
174               the ready queue. The job will be in the "delayed" state during
175               this time
176
177       bury ($id [, $options])
178           The bury command puts a job into the "buried" state. Buried jobs
179           are put into a FIFO linked list and will not be touched by the
180           server again until a client kicks them with the "kick" command.
181
182           Valid options are
183
184           priority
185               New priority to assign to the job
186
187       touch ($id)
188           Calling "touch" with the id of a reserved job will reset the time
189           left for the job to complete back to the original ttr value.
190
191       watch ($tube)
192           Specifies a tube to add to the watch list. If the tube doesn't
193           exist, it will be created
194
195       ignore ($tube)
196           Stop watching $tube
197
198       watch_only (@tubes)
199           Watch only the list of given tube names
200
201   Other Methods
202       connect
203           Connect to server. If sucessful, set the tube to use and tube to
204           watch if a "default_tube" was specified.
205
206       disconnect
207           Disconnect from server. "socket" method will return undef.
208
209       quit
210           Disconnect from server. "socket" method will return undef.
211
212       peek ($id)
213           Peek at the job id specified. If the job exists returns a
214           Beanstalk::Job object. Returns "undef" on error or if job does not
215           exist.
216
217       peek_ready
218           Peek at the first job that is in the ready queue. If there is a job
219           in the ready queue returns a Beanstalk::Job object. Returns "undef"
220           on error or if there are no ready jobs.
221
222       peek_delayed
223           Peek at the first job that is in the delayed queue. If there is a
224           job in the delayed queue returns a Beanstalk::Job object. Returns
225           "undef" on error or if there are no delayed jobs.
226
227       peek_buried
228           Peek at the first job that is in the buried queue. If there is a
229           job in the buried queue returns a Beanstalk::Job object. Returns
230           "undef" on error or if there are no buried jobs.
231
232       kick ($bound)
233           The kick command applies only to the currently used tube. It moves
234           jobs into the ready queue. If there are any buried jobs, it will
235           only kick buried jobs.  Otherwise it will kick delayed jobs. The
236           server will not kick more than $bound jobs. Returns the number of
237           jobs kicked, or undef if there was an error.
238
239       stats_job ($id)
240           Return stats for the specified job $id. Returns "undef" on error.
241
242           If the job exists, the return will be a Stats object with the
243           following methods
244
245           ·   id - The job id
246
247           ·   tube - The name of the tube that contains this job
248
249           ·   state - is "ready" or "delayed" or "reserved" or "buried"
250
251           ·   pri - The priority value set by the put, release, or bury
252               commands.
253
254           ·   age - The time in seconds since the put command that created
255               this job.
256
257           ·   time_left - The number of seconds left until the server puts
258               this job into the ready queue. This number is only meaningful
259               if the job is reserved or delayed. If the job is reserved and
260               this amount of time elapses before its state changes, it is
261               considered to have timed out.
262
263           ·   reserves - The number of times this job has been reserved
264
265           ·   timeouts - The number of times this job has timed out during a
266               reservation.
267
268           ·   releases - The number of times a client has released this job
269               from a reservation.
270
271           ·   buries - The number of times this job has been buried.
272
273           ·   kicks - The number of times this job has been kicked.
274
275       stats_tube ($tube)
276           Return stats for the specified tube $tube. Returns "undef" on
277           error.
278
279           If the tube exists, the return will be a Stats object with the
280           following methods
281
282           ·   name - The tube's name.
283
284           ·   current_jobs_urgent - The number of ready jobs with priority <
285               1024 in this tube.
286
287           ·   current_jobs_ready - The number of jobs in the ready queue in
288               this tube.
289
290           ·   current_jobs_reserved - The number of jobs reserved by all
291               clients in this tube.
292
293           ·   current_jobs_delayed - The number of delayed jobs in this tube.
294
295           ·   current_jobs_buried - The number of buried jobs in this tube.
296
297           ·   total_jobs - The cumulative count of jobs created in this tube.
298
299           ·   current_waiting - The number of open connections that have
300               issued a reserve command while watching this tube but not yet
301               received a response.
302
303           ·   pause - The number of seconds the tube has been paused for.
304
305           ·   cmd_pause_tube - The cumulative number of pause-tube commands
306               for this tube.
307
308           ·   pause_time_left - The number of seconds until the tube is un-
309               paused.
310
311       stats
312           ·   current_jobs_urgent - The number of ready jobs with priority <
313               1024.
314
315           ·   current_jobs_ready - The number of jobs in the ready queue.
316
317           ·   current_jobs_reserved - The number of jobs reserved by all
318               clients.
319
320           ·   current_jobs_delayed - The number of delayed jobs.
321
322           ·   current_jobs_buried - The number of buried jobs.
323
324           ·   cmd_put - The cumulative number of put commands.
325
326           ·   cmd_peek - The cumulative number of peek commands.
327
328           ·   cmd_peek_ready - The cumulative number of peek-ready commands.
329
330           ·   cmd_peek_delayed - The cumulative number of peek-delayed
331               commands.
332
333           ·   cmd_peek_buried - The cumulative number of peek-buried
334               commands.
335
336           ·   cmd_reserve - The cumulative number of reserve commands.
337
338           ·   cmd_use - The cumulative number of use commands.
339
340           ·   cmd_watch - The cumulative number of watch commands.
341
342           ·   cmd_ignore - The cumulative number of ignore commands.
343
344           ·   cmd_delete - The cumulative number of delete commands.
345
346           ·   cmd_release - The cumulative number of release commands.
347
348           ·   cmd_bury - The cumulative number of bury commands.
349
350           ·   cmd_kick - The cumulative number of kick commands.
351
352           ·   cmd_stats - The cumulative number of stats commands.
353
354           ·   cmd_stats_job - The cumulative number of stats-job commands.
355
356           ·   cmd_stats_tube - The cumulative number of stats-tube commands.
357
358           ·   cmd_list_tubes - The cumulative number of list-tubes commands.
359
360           ·   cmd_list_tube_used - The cumulative number of list-tube-used
361               commands.
362
363           ·   cmd_list_tubes_watched - The cumulative number of list-tubes-
364               watched commands.
365
366           ·   cmd_pause_tube - The cumulative number of pause-tube commands
367
368           ·   job_timeouts - The cumulative count of times a job has timed
369               out.
370
371           ·   total_jobs - The cumulative count of jobs created.
372
373           ·   max_job_size - The maximum number of bytes in a job.
374
375           ·   current_tubes - The number of currently-existing tubes.
376
377           ·   current_connections - The number of currently open connections.
378
379           ·   current_producers - The number of open connections that have
380               each issued at least one put command.
381
382           ·   current_workers - The number of open connections that have each
383               issued at least one reserve command.
384
385           ·   current_waiting - The number of open connections that have
386               issued a reserve command but not yet received a response.
387
388           ·   total_connections - The cumulative count of connections.
389
390           ·   pid - The process id of the server.
391
392           ·   version - The version string of the server.
393
394           ·   rusage_utime - The accumulated user CPU time of this process in
395               seconds and microseconds.
396
397           ·   rusage_stime - The accumulated system CPU time of this process
398               in seconds and microseconds.
399
400           ·   uptime - The number of seconds since this server started
401               running.
402
403           ·   binlog_oldest_index - The index of the oldest binlog file
404               needed to store the current jobs
405
406           ·   binlog_current_index - The index of the current binlog file
407               being written to. If binlog is not active this value will be 0
408
409           ·   binlog_max_size - The maximum size in bytes a binlog file is
410               allowed to get before a new binlog file is opened
411
412       list_tubes
413           Returns a list of tubes
414
415       list_tube_used
416           Returns the current tube being used. This is the tube which "put"
417           will place jobs.
418
419       list_tubes_watched
420           Returns a list of tubes being watched, or the number of tubes being
421           watched in a scalar context.  These are the tubes that "reserve"
422           will check to find jobs. On error an empty list, or undef in a
423           scalar context, will be returned.
424
425       pause_tube ($tube, $delay)
426           Pause from reserving any jobs in $tube for $delay seconds.
427
428           Returns true on success and "undef" on error.
429

TODO

431       More tests
432

ACKNOWLEDGEMTS

434       Large parts of this documention were lifted from the documention that
435       comes with beanstalkd
436

SEE ALSO

438       http://xph.us/software/beanstalkd/
439
440       Beanstalk::Pool, Beanstalk::Job, Beanstalk::Stats
441

AUTHOR

443       Graham Barr <gbarr@pobox.com>
444

CREDITS

446       ·   Ask Bjorn Hansen
447
448       ·   Rhesa Rozendaal
449
451       Copyright (C) 2008 by Graham Barr.
452
453       This program is free software; you can redistribute it and/or modify it
454       under the same terms as Perl itself.
455
456
457
458perl v5.12.1                      2009-12-11              Beanstalk::Client(3)
Impressum