Beanstalk::Client(3)
π Beanstalk::Client(3) π
Okay bestie, welcome to the User Contributed Perl Documentation page for Beanstalk::Client(3). This is the client class that talks to the beanstalkd server, and it's giving main character energy fr fr. β¨
β¨ NAME β¨
Beanstalk::Client β Client class to talk to beanstalkd server. That's the whole name, no cap. π
πΈ SYNOPSIS πΈ
Here's the code vibe check, bestie:
use Beanstalk::Client;
my $client = Beanstalk::Client->new(
{ server => "localhost",
default_tube => 'mine',
}
);
# Send a job with explicit data
my $job = $client->put(
{ data => "data",
priority => 100,
ttr => 120,
delay => 5,
}
);
# Send job, data created by encoding @args. By default with YAML
my $job2 = $client->put(
{ priority => 100,
ttr => 120,
delay => 5,
},
@args
);
# Send job, data created by encoding @args with JSON
use JSON::XS;
$client->encoder(sub { encode_json(\@_) });
my $job2 = $client->put(
{ priority => 100,
ttr => 120,
delay => 5,
},
@args
);
# fetch a job
my $job3 = $client->reserve;
π¦ DESCRIPTION π¦
Beanstalk::Client provides a Perl API of protocol version 1.0 to the beanstalkd server, a fast, general-purpose, in-memory workqueue service by Keith Rarick. Periodt. π
π METHODS π
π§ Constructor π§
new ($options)β The constructor accepts a single argument, which is a reference to a hash containing options. The options can be any of the accessor methods listed below. So basically, you pass a hashref and it's game time. π
π Accessor Methods π
server ([$hostname])β Get/set the hostname, and port, to connect to. The port, which defaults to11300, can be specified by appending it to the hostname with a":"(eg"localhost:1234"). (Default:"localhost:11300")socketβ Get the socket connection to the server.delay ([$delay])β Set/get a default value, in seconds, for job delay. A job with a delay will be placed into a delayed state and will not be placed into the ready queue until the time period has passed. This value will be used by"put"and"release"as a default. (Default:0)ttr ([$ttr])β Set/get a default value, in seconds, for jobttr(time to run). This value will be used by"put"as a default. (Default:120)priority ([$priority])β Set/get a default value for job priority. The highest priority job is the job where the priority value is the lowest (ie jobs with a lower priority value are run first). This value will be used by"put","release"and"bury"as a default. (Default:10000)encoder ([$encoder])β Set/get serialization encoder.$encoderis a reference to a subroutine that will be called when arguments to"put"need to be encoded to send to the beanstalkd server. The subroutine should accept a list of arguments and return a string representation to pass to the server. (Default:YAML::Syck::Dump)decoder ([$decoder])β Set/get the serialization decoder.$decoderis a reference to a subroutine that will be called when data from the beanstalkd server needs to be decoded. The subroutine will be passed the data fetched from the beanstalkd server and should return a list of values the application can use. (Default:YAML::Syck::Load)errorβ Fetch the last error that happened.connect_timeout ([$timeout])β Get/set timeout, in seconds, to use for the connect to the server.default_tube ([$tube])β Set/get the name of a default tube to put jobs into and fetch from.
By default a connection to a beanstalkd server will put into the "default" queue and also watch the "default" queue. If "default_tube" is set when "connect" is called the connection will be initialized so that "put" will put into the given tube and "reserve" will fetch jobs from the given tube. (Default: none)
debug ([$debug])β Set/get debug value. If set to a true value then all communication with the server will be output with"warn"
π Producer Methods π
These methods are used by clients that are placing work into the queue.
put ($options [, @args])β Insert job into the currently used tube. Options may be:priorityβ priority to use to queue the job. Jobs with smaller priority values will be scheduled before jobs with larger priorities. The most urgent priority is0. Defaults to"$self-"priority>.delayβ An integer number of seconds to wait before putting the job in the ready queue. The job will be in the"delayed"state during this time. Defaults to"$self-"delay>.ttr"time to run" β An integer number of seconds to allow a worker to run this job. This time is counted from the moment a worker reserves this job. If the worker does not delete, release, or bury the job within"ttr"seconds, the job will time out and the server will release the job. The minimum ttr is1. If the client sends0, the server will silently increase the ttr to1.dataβ The job body. Defaults to the result of calling the current encoder passing@args.
use ($tube)β Change tube that new jobs are inserted into.
π Worker Methods π
reserve ([$timeout])β Reserve a job from the list of tubes currently being watched.
Returns a Beanstalk::Job on success. $timeout is the maximum number of seconds to wait for a job to become ready. If $timeout is not given then the client will wait indefinitely.
Returns undef on error or if $timeout expires.
delete ($id)β Delete the specified job.release ($id, [, $options])β Release the specified job. Valid options are:priorityβ New priority to assign to the job.delayβ An integer number of seconds to wait before putting the job in the ready queue. The job will be in the"delayed"state during this time.
bury ($id [, $options])β The bury command puts a job into the"buried"state. Buried jobs are put into a FIFO linked list and will not be touched by the server again until a client kicks them with the"kick"command.
Valid options are:
priorityβ New priority to assign to the job.
touch ($id)β Calling"touch"with the id of a reserved job will reset the time left for the job to complete back to the original ttr value.watch ($tube)β Specifies a tube to add to the watch list. If the tube doesn't exist, it will be createdignore ($tube)β Stop watching$tubewatch_only (@tubes)β Watch only the list of given tube names
β¨ Other Methods β¨
connectβ Connect to server. If sucessful, set the tube to use and tube to watch if a"default_tube"was specified.disconnectβ Disconnect from server."socket"method will returnundef.quitβ Disconnect from server."socket"method will returnundef.peek ($id)β Peek at the job id specified. If the job exists returns aBeanstalk::Jobobject. Returns"undef"on error or if job does not exist.peek_readyβ Peek at the first job that is in the ready queue. If there is a job in the ready queue returns aBeanstalk::Jobobject. Returns"undef"on error or if there are no ready jobs.peek_delayedβ Peek at the first job that is in the delayed queue. If there is a job in the delayed queue returns aBeanstalk::Jobobject. Returns"undef"on error or if there are no delayed jobs.peek_buriedβ Peek at the first job that is in the buried queue. If there is a job in the buried queue returns aBeanstalk::Jobobject. Returns"undef"on error or if there are no buried jobs.kick ($bound)β The kick command applies only to the currently used tube. It moves jobs into the ready queue. If there are any buried jobs, it will only kick buried jobs. Otherwise it will kick delayed jobs. The server will not kick more than$boundjobs. Returns the number of jobs kicked, orundefif there was an error.kick_job ($id)β The kick-job command is a variant of kick that operats with a single job identified by its job id. If the given job id exists and is in a buried or delayed state, it will be moved to the ready queue of the same tube where it currently belongs. Returns"undef"on error.
Note: the kick_job command was only introduced on version 1.8 of beanstalk. If you have a version of beanstalk prior to this then the command will return an error.
stats_job ($id)β Return stats for the specified job$id. Returns"undef"on error.
If the job exists, the return will be a Stats object with the following methods:
id- The job idtube- The name of the tube that contains this jobstate- is"ready"or"delayed"or"reserved"or"buried"pri- The priority value set by the put, release, or bury commands.age- The time in seconds since the put command that created this job.time_left- The number of seconds left until the server puts this job into the ready queue. This number is only meaningful if the job is reserved or delayed. If the job is reserved and this amount of time elapses before its state changes, it is considered to have timed out.reserves- The number of times this job has been reservedtimeouts- The number of times this job has timed out during a reservation.releases- The number of times a client has released this job from a reservation.buries- The number of times this job has been buried.kicks- The number of times this job has been kicked.
stats_tube ($tube)β Return stats for the specified tube$tube. Returns"undef"on error.
If the tube exists, the return will be a Stats object with the following methods:
name- The tube's name.current_jobs_urgent- The number of ready jobs with priority <1024in this tube.current_jobs_ready- The number of jobs in the ready queue in this tube.current_jobs_reserved- The number of jobs reserved by all clients in this tube.current_jobs_delayed- The number of delayed jobs in this tube.current_jobs_buried- The number of buried jobs in this tube.total_jobs- The cumulative count of jobs created in this tube.current_waiting- The number of open connections that have issued a reserve command while watching this tube but not yet received a response.pause- The number of seconds the tube has been paused for.
That's where part 1 wraps, bestie β part 2 is loading with even more methods. Stay tuned. π
cmd_pause_tubeβ the cumulative number of pause-tube commands for this tube. πpause_time_leftβ how many seconds are left until this tube gets un-paused. tick tock bestie β³
stats π
okay so stats hands you the whole server-tea, and every single one of these keys is in the mix:
current_jobs_urgentβ how many ready jobs there are with priority < 1024. π¨current_jobs_readyβ how many jobs are chilling in the ready queue.current_jobs_reservedβ how many jobs are reserved by all the clients, collectively.current_jobs_delayedβ how many delayed jobs exist rn.current_jobs_buriedβ how many jobs are buried. πͺ¦cmd_putβ the cumulative number ofputcommands.cmd_peekβ the cumulative number ofpeekcommands.cmd_peek_readyβ the cumulative number of peek-ready commands.cmd_peek_delayedβ the cumulative number of peek-delayed commands.cmd_peek_buriedβ the cumulative number of peek-buried commands.cmd_reserveβ the cumulative number of reserve commands.cmd_useβ the cumulative number of use commands.cmd_watchβ the cumulative number of watch commands.cmd_ignoreβ the cumulative number of ignore commands.cmd_deleteβ the cumulative number of delete commands.cmd_releaseβ the cumulative number of release commands.cmd_buryβ the cumulative number of bury commands.cmd_kickβ the cumulative number of kick commands.cmd_statsβ the cumulative number of stats commands.cmd_stats_jobβ the cumulative number of stats-job commands.cmd_stats_tubeβ the cumulative number of stats-tube commands.cmd_list_tubesβ the cumulative number of list-tubes commands.cmd_list_tube_usedβ the cumulative number of list-tube-used commands.cmd_list_tubes_watchedβ the cumulative number of list-tubes-watched commands.cmd_pause_tubeβ the cumulative number of pause-tube commands. (no period on this one in the original, and we respect the lore β¨)job_timeoutsβ the cumulative count of times a job has timed out. πtotal_jobsβ the cumulative count of jobs created, ever.max_job_sizeβ the maximum number of bytes in a job.current_tubesβ how many tubes currently exist.current_connectionsβ how many connections are currently open.current_producersβ how many open connections have each issued at least oneputcommand.current_workersβ how many open connections have each issued at least onereservecommand. πͺcurrent_waitingβ how many open connections have issued areservecommand but haven't gotten a response yet. the anticipation fr πtotal_connectionsβ the cumulative count of connections.pidβ the process id of the server.versionβ the version string of the server.rusage_utimeβ the accumulated user CPU time of this process, in seconds and microseconds.rusage_stimeβ the accumulated system CPU time of this process, in seconds and microseconds.uptimeβ the number of seconds since this server started running.binlog_oldest_indexβ the index of the oldest binlog file needed to store the current jobs.binlog_current_indexβ the index of the current binlog file being written to. if binlog is not active, this value will be0. noted πbinlog_max_sizeβ the maximum size in bytes a binlog file is allowed to get before a new binlog file is opened.
list_tubes π
Returns a list of tubes. that's it, that's the whole vibe.
list_tube_used πΈ
Returns the current tube being used. This is the tube that put will place jobs into. iykyk.
list_tubes_watched π
Returns a list of tubes being watched β or, in a scalar context, the number of tubes being watched. These are the tubes that reserve will check to find jobs. On error you get an empty list, or undef in a scalar context. so like, watch out π«Ά
pause_tube ($tube, $delay) β
Pause from reserving any jobs in $tube for $delay seconds.
Returns true on success and undef on error.
TODO π
- More tests
bestie that's the entire TODO section. not me feeling seen π
ACKNOWLEDGEMTS π
Large parts of this documention were lifted from the documention that comes with beanstalkd. (yes the heading is spelled like that, we are keeping it exactly as it is, no edits, periodt β¨)
SEE ALSO π
http://kr.github.com/beanstalkd/
Beanstalk::Pool, Beanstalk::Job, Beanstalk::Stats
AUTHOR βοΈ
Graham Barr <gbarr@pobox.com>
CREDITS π
- Ask BjΓΈrn Hansen
- Rhesa Rozendaal
- Ian Docherty
BUGS π
The Git repository is available at http://github.com/gbarr/perl-beanstalk-client
Please report any bugs or feature requests to the issue tracker at http://github.com/gbarr/perl-beanstalk-client/issues
COPYRIGHT Β©οΈ
Copyright (C) 2008-2012 by Graham Barr.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie, we ate and left no crumbs π
β¨ this lil beauty is perl v5.42.0 flavoured, dated 2025-07-25, and it lives at Beanstalk::Client(3). go forth and reserve responsibly π¦π
π¦ where this page comes from
- fedora 43: perl-Beanstalk-Client 1.07-36.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms