GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  BEANSTALK::CLIENT (3)

.ds Aq ’

NAME

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

CONTENTS

SYNOPSIS



  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.

METHODS

    Constructor

<B>new ($options)B> 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.

    Accessor Methods

<B>server ([$hostname])B> Get/set the hostname, and port, to connect to. The port, which defaults to 11300, can be specified by appending it to the hostname with a : (eg "localhost:1234"). (Default: localhost:11300)
<B>socketB> Get the socket connection to the server.
<B>delay ([$delay])B> 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)
<B>ttr ([$ttr])B> Set/get a default value, in seconds, for job ttr (time to run). This value will be used by put as a default. (Default: 120)
<B>priority ([$priority])B> 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)
<B>encoder ([$encoder])B> Set/get serialization encoder. $encoder is 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)
<B>decoder ([$decoder])B> Set/get the serialization decoder. $decoder is 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)
<B>errorB> Fetch the last error that happened.
<B>connect_timeout ([$timeout])B> Get/set timeout, in seconds, to use for the connect to the server.
<B>default_tube ([$tube])B> 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)

<B>debug ([$debug])B> 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
<B>put ($options [, B>@args<B>])B> 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 is 0

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 is 1. If the client sends 0, the server will silently increase the ttr to 1.
data The job body. Defaults to the result of calling the current encoder passing @args
<B>use ($tube)B> Change tube that new jobs are inserted into

    Worker Methods

<B>reserve ([$timeout])B> 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.

<B>delete ($id)B> Delete the specified job.
<B>release ($id, [, B>$options<B>])B> 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
<B>bury ($id [, B>$options<B>])B> 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

<B>touch ($id)B> 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.
<B>watch ($tube)B> Specifies a tube to add to the watch list. If the tube doesn’t exist, it will be created
<B>ignore ($tube)B> Stop watching $tube
<B>watch_only (@tubes)B> Watch only the list of given tube names

    Other Methods

<B>connectB> Connect to server. If sucessful, set the tube to use and tube to watch if a default_tube was specified.
<B>disconnectB> Disconnect from server. socket method will return undef.
<B>quitB> Disconnect from server. socket method will return undef.
<B>peek ($id)B> Peek at the job id specified. If the job exists returns a Beanstalk::Job object. Returns undef on error or if job does not exist.
<B>peek_readyB> Peek at the first job that is in the ready queue. If there is a job in the ready queue returns a Beanstalk::Job object. Returns undef on error or if there are no ready jobs.
<B>peek_delayedB> Peek at the first job that is in the delayed queue. If there is a job in the delayed queue returns a Beanstalk::Job object. Returns undef on error or if there are no delayed jobs.
<B>peek_buriedB> Peek at the first job that is in the buried queue. If there is a job in the buried queue returns a Beanstalk::Job object. Returns undef on error or if there are no buried jobs.
<B>kick ($bound)B> 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 $bound jobs. Returns the number of jobs kicked, or undef if there was an error.
<B>stats_job ($id)B> 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
o <B>idB> - The job id
o <B>tubeB> - The name of the tube that contains this job
o <B>stateB> - is ready or delayed or reserved or buried
o <B>priB> - The priority value set by the put, release, or bury commands.
o <B>ageB> - The time in seconds since the put command that created this job.
o <B>time_leftB> - 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.
o <B>reservesB> - The number of times this job has been reserved
o <B>timeoutsB> - The number of times this job has timed out during a reservation.
o <B>releasesB> - The number of times a client has released this job from a reservation.
o <B>buriesB> - The number of times this job has been buried.
o <B>kicksB> - The number of times this job has been kicked.

<B>stats_tube ($tube)B> 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
o <B>nameB> - The tube’s name.
o <B>current_jobs_urgentB> - The number of ready jobs with priority < 1024 in this tube.
o <B>current_jobs_readyB> - The number of jobs in the ready queue in this tube.
o <B>current_jobs_reservedB> - The number of jobs reserved by all clients in this tube.
o <B>current_jobs_delayedB> - The number of delayed jobs in this tube.
o <B>current_jobs_buriedB> - The number of buried jobs in this tube.
o <B>total_jobsB> - The cumulative count of jobs created in this tube.
o <B>current_waitingB> - The number of open connections that have issued a reserve command while watching this tube but not yet received a response.
o <B>pauseB> - The number of seconds the tube has been paused for.
o <B>cmd_pause_tubeB> - The cumulative number of pause-tube commands for this tube.
o <B>pause_time_leftB> - The number of seconds until the tube is un-paused.

<B>statsB>
o <B>current_jobs_urgentB> - The number of ready jobs with priority < 1024.
o <B>current_jobs_readyB> - The number of jobs in the ready queue.
o <B>current_jobs_reservedB> - The number of jobs reserved by all clients.
o <B>current_jobs_delayedB> - The number of delayed jobs.
o <B>current_jobs_buriedB> - The number of buried jobs.
o <B>cmd_putB> - The cumulative number of put commands.
o <B>cmd_peekB> - The cumulative number of peek commands.
o <B>cmd_peek_readyB> - The cumulative number of peek-ready commands.
o <B>cmd_peek_delayedB> - The cumulative number of peek-delayed commands.
o <B>cmd_peek_buriedB> - The cumulative number of peek-buried commands.
o <B>cmd_reserveB> - The cumulative number of reserve commands.
o <B>cmd_useB> - The cumulative number of use commands.
o <B>cmd_watchB> - The cumulative number of watch commands.
o <B>cmd_ignoreB> - The cumulative number of ignore commands.
o <B>cmd_deleteB> - The cumulative number of delete commands.
o <B>cmd_releaseB> - The cumulative number of release commands.
o <B>cmd_buryB> - The cumulative number of bury commands.
o <B>cmd_kickB> - The cumulative number of kick commands.
o <B>cmd_statsB> - The cumulative number of stats commands.
o <B>cmd_stats_jobB> - The cumulative number of stats-job commands.
o <B>cmd_stats_tubeB> - The cumulative number of stats-tube commands.
o <B>cmd_list_tubesB> - The cumulative number of list-tubes commands.
o <B>cmd_list_tube_usedB> - The cumulative number of list-tube-used commands.
o <B>cmd_list_tubes_watchedB> - The cumulative number of list-tubes-watched commands.
o <B>cmd_pause_tubeB> - The cumulative number of pause-tube commands
o <B>job_timeoutsB> - The cumulative count of times a job has timed out.
o <B>total_jobsB> - The cumulative count of jobs created.
o <B>max_job_sizeB> - The maximum number of bytes in a job.
o <B>current_tubesB> - The number of currently-existing tubes.
o <B>current_connectionsB> - The number of currently open connections.
o <B>current_producersB> - The number of open connections that have each issued at least one put command.
o <B>current_workersB> - The number of open connections that have each issued at least one reserve command.
o <B>current_waitingB> - The number of open connections that have issued a reserve command but not yet received a response.
o <B>total_connectionsB> - The cumulative count of connections.
o <B>pidB> - The process id of the server.
o <B>versionB> - The version string of the server.
o <B>rusage_utimeB> - The accumulated user CPU time of this process in seconds and microseconds.
o <B>rusage_stimeB> - The accumulated system CPU time of this process in seconds and microseconds.
o <B>uptimeB> - The number of seconds since this server started running.
o <B>binlog_oldest_indexB> - The index of the oldest binlog file needed to store the current jobs
o <B>binlog_current_indexB> - The index of the current binlog file being written to. If binlog is not active this value will be 0
o <B>binlog_max_sizeB> - The maximum size in bytes a binlog file is allowed to get before a new binlog file is opened
<B>list_tubesB> Returns a list of tubes
<B>list_tube_usedB> Returns the current tube being used. This is the tube which put will place jobs.
<B>list_tubes_watchedB> Returns a list of tubes being watched, or the number of tubes being watched in a scalar context. These are the tubes that reserve will check to find jobs. On error an empty list, or undef in a scalar context, will be returned.
<B>pause_tube ($tube, B>$delay<B>)B> Pause from reserving any jobs in $tube for $delay seconds.

Returns true on success and undef on error.

TODO

More tests

ACKNOWLEDGEMTS

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

SEE ALSO

http://xph.us/software/beanstalkd/

Beanstalk::Pool, Beanstalk::Job, Beanstalk::Stats

AUTHOR

Graham Barr <gbarr@pobox.com>

CREDITS

o Ask Bjo\k:/rn Hansen
o Rhesa Rozendaal

COPYRIGHT

Copyright (C) 2008 by Graham Barr.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 BEANSTALK::CLIENT (3) 2009-12-11

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.