Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
Queue::Beanstalk(3)   User Contributed Perl Documentation  Queue::Beanstalk(3)

       Queue::Beanstalk	- Client library for the beanstalkd server

       Producer	example:

	 use Queue::Beanstalk;

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

	 # Adds	a job with priority 4294967295 and 0 delay

	 # 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' =>  [	'' ],
					'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

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

       Has the following hashref options:

	   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.

	   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.

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

	   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.

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

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

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

       $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'.


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


       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.

       $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 the current reserved job.	Removes	the job	from the queue as the
       job is finished.

       Haakon Nessjoen,	Loopback Systems AS, <>

       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.

       Hey! The	above document had some	coding errors, which are explained

       Around line 620:
	   Non-ASCII character seen before =encoding in	'Haakon'. Assuming

perl v5.32.0			  2020-08-09		   Queue::Beanstalk(3)


Want to link to this manual page? Use this URL:

home | help