2017 © Pedro PelĆ”ez
 

library queue-beanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

image

slm/queue-beanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  • Thursday, July 30, 2015
  • by juriansluiman
  • Repository
  • 4 Watchers
  • 9 Stars
  • 34,692 Installations
  • PHP
  • 1 Dependents
  • 2 Suggesters
  • 24 Forks
  • 15 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

SlmQueueBeanstalkd

Build Status Latest Stable Version Latest Unstable Version, (*1)

Created by Jurian Sluiman and Michaƫl Gallego, (*2)

Requirements

Installation

First, install SlmQueue (instructions here). Then, add the following line into your composer.json file:, (*3)

"require": {
    "slm/queue-beanstalkd": "0.4.*"
}

Then, enable the module by adding SlmQueueBeanstalkd in your application.config.php file. You may also want to configure the module: just copy the slm_queue_beanstalkd.local.php.dist (you can find this file in the config folder of SlmQueueBeanstalkd) into your config/autoload folder, and override what you want., (*4)

Documentation

Before reading SlmQueueBeanstalkd documentation, please read SlmQueue documentation., (*5)

(Don't forget to first install Beanstalkd, and to run the daemon program on the server), (*6)

Setting the connection parameters

Copy the slm_queue_beanstalkd.local.php.dist file to your config/autoload folder, and follow the instructions., (*7)

Adding queues

SlmQueueBeanstalkd provides an interface for a queue that implements SlmQueue\Queue\QueueInterface and provides in addition the following methods:, (*8)

  • release(JobInterface $job, array $options = array()): when a job fails, you can add the job again to the queue by releasing it, so that it can have another chance to be executed.
  • bury(JobInterface $job, array $options = array()): when a job fails and that it has not been manually released, it is automatically buried.
  • kick($max): when this method is called, it will move a maximum of $max buried jobs back to the queue.

A concrete class that implements this interface is included: SlmQueueBeanstalkd\Queue\BeanstalkdQueue and a factory is available to create the queue. Therefore, if you want to have a queue called "email", just add the following line in your module.config.php file:, (*9)

return array(
    'slm_queue' => array(
        'queue_manager' => array(
            'factories' => array(
                'email' => 'SlmQueueBeanstalkd\Factory\BeanstalkdQueueFactory'
            )
        )
    )
);

This queue can therefore be pulled from the QueuePluginManager class., (*10)

Operations on queues

push

Valid options are:, (*11)

  • priority: the lower the priority is, the sooner the job get popped from the queue (default to 1024)
  • delay: the delay in seconds before a job become available to be popped (default to 0 - no delay -)
  • ttr: in seconds, how much time a job can be reserved for (default to 60)

Example:, (*12)

$queue->push($job, array(
    'priority' => 20,
    'delay'    => 23,
    'ttr'      => 50
));

pop

Valid option is:, (*13)

  • timeout: by default, when we ask for a job, it will block until a job is found (possibly forever if new jobs never come). If you set a timeout (in seconds), it will return after the timeout is expired, even if no jobs were found

release

Valid options are:, (*14)

  • priority: the lower the priority is, the sooner the job get popped from the queue (default to 1024)
  • delay: the delay in seconds before a job become available to be popped (default to 0 - no delay -)

bury

Valid option is:, (*15)

  • priority: the lower the priority is, the sooner the job get kicked

How to bury/release a job

Beanstalkd offers a nice bury/kick/release mechanism, so that jobs that fail can have a second chance to be executed. SlmQueueBeanstalkd provides a nice way to easily bury/release a job. In fact, you just need to throw either the SlmQueueBeanstalkd\Job\Exception\BuryableException or SlmQueueBeanstalkd\Job\Exception\ReleasableException in the execute method of your job:, (*16)

use SlmQueue\Job\AbstractJob;
use SlmQueueBeanstalkd\Job\Exception;

class SimpleJob extends AbstractJob
{
    public function execute()
    {
        // Bury the job, with a priority of 10
        throw new Exception\BuryableException(array('priority' => 10));

        // Release the job, with a priority of 10 and delay of 5 seconds
        throw new Exception\ReleasableException(array('priority' => 10, 'delay' => 5));
    }
}

Executing jobs

SlmQueueBeanstalkd provides a command-line tool that can be used to pop and execute jobs. You can type the following command within the public folder of your Zend Framework 2 application:, (*17)

php index.php queue beanstalkd <queue> [--timeout=], (*18)

The queue is a mandatory parameter, while the timeout is an optional flag that specifies the duration in seconds for which the call will wait for a job to arrive in the queue before returning (because the script can wait forever if no job come)., (*19)

The Versions

28/10 2014

dev-hotfix/readme-wrong-queue-name

dev-hotfix/readme-wrong-queue-name https://github.com/juriansluiman/SlmQueueBeanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 queue beanstalk job beanstalkd pheanstalk

08/10 2014

dev-feature/extract-job-hydration

dev-feature/extract-job-hydration https://github.com/juriansluiman/SlmQueueBeanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 queue beanstalk job beanstalkd pheanstalk

24/07 2014

dev-feature/job-status

dev-feature/job-status https://github.com/juriansluiman/SlmQueueBeanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 queue beanstalk job beanstalkd pheanstalk

05/05 2014
30/03 2014
22/01 2014

0.3.0-beta1

0.3.0.0-beta1 https://github.com/juriansluiman/SlmQueueBeanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 queue beanstalk job beanstalkd pheanstalk

14/02 2013

0.2.1

0.2.1.0 https://github.com/juriansluiman/SlmQueueBeanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  Sources   Download

The Requires

 

zf2 queue beanstalk job beanstalkd pheanstalk

09/02 2013

0.2

0.2.0.0 https://github.com/juriansluiman/SlmQueueBeanstalkd

Zend Framework 2 module that integrates with Beanstalkd queuing system

  Sources   Download

The Requires

 

zf2 queue beanstalk job beanstalkd pheanstalk