NAME

Queue::Beanstalk - Client library for the beanstalkd server

SYNOPSIS

Producer example:

use Queue::Beanstalk;

$jobs = Queue::Beanstalk->new(
                               'servers' =>  [ '127.0.0.1:11300' ],
                               'connect_timeout' => 2,
);

# Adds a job with priority 4294967295 and 0 delay  
$jobs->put('do:something');

# Adds a job with 0 (highest) priority and 1 second delay
$jobs->put(('do:somethingelse', 0, 1);

Worker example:

use Queue::Beanstalk;

$jobs = Queue::Beanstalk->new(
                               'servers' =>  [ '127.0.0.1:11300' ],
                               'connect_timeout' => 2,
);

while (1) {
  my $data;
  
  if ($data = $jobs->reserve()) {

    if (do_something($data)) {
      $jobs->delete();  # done with the job
    } else {
      $jobs->release(); # i failed, let someone else take it
    }
    $jobs->next_server(); # optional, if you have several servers

  }

  sleep(1); # prevent cpu intensive loop (just in case)
}

WARNING! This module is marked as being in the alpha stage, and is therefore subject to change in near future. This version of Queue::Beanstalk currently supports the 0.6 protocol version of Beanstalkd.

DESCRIPTION

Client library for Beanstalk. Read more about the Beanstalkd daemon at

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

CONSTRUCTOR

new

Has the following hashref options:

servers

An arrayref of servers that can be connected to. Must be in the host:port format. By default the module wil randomly select a server to connect to. You can change this behaviour with the random_servers option.

random_servers

If given a false value, the module will follow the order of the servers array and select the next server in the list on subsequent calls to next_server(); When using this module as a 'producer', it is best to leave the default value of true, so the clients will randomly connect to one of your beantalkd servers.

auto_next_server

Will automatically go to the next or a random server after a successful put or delete. Default value is false.

report_errors

When given a false value, the module will not give any errormessages out loud. And will only exit the functions with an undefined value, the corresponding error-messages however will be found in the 'errstr' variable of the object.

connect_timeout

Amount of seconds to wait for a connection to go through. Default is 0.25 second.

select_timeout

Amount of seconds to wait for a socket to have data available. Default is 1 second.

reserve_timeout

Amount of seconds to wait for an available job to reserve. Default is 10 seconds.

METHODS

put

$jobs->put($job_data[, $priority, $delay])

Insert a job into the queue. Priority is an integer between 0 (highest) and 4294967295 (lowest). Default priority is 4294967295. Default delay is 0.

Returns an undefined value on errors, 'inserted' or 'burried'.

stats

$jobs->stats();

Returns YAML stats output from beanstalkd. TODO: Parse yaml and return hashref.

reserve

$jobs->reserve();

Returns undef on failure/timeout, or full job-data if successful. You have 120 seconds to fullfil the job, before beanstalkd gives up on you.

release

$jobs->release([$priority, $delay]);

Release the current reserved job. The default is to use the same priority as the job had, and 0 second delay.

delete

$jobs->delete();

Delete the current reserved job. Removes the job from the queue as the job is finished.

AUTHOR

Håkon Nessjøen, Loopback Systems AS, <lunatic@cpan.org>

COPYRIGHT AND LICENSE

Copyright (c) 2007 by Loopback Systems AS

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 620:

Non-ASCII character seen before =encoding in 'Håkon'. Assuming CP1252