2017 © Pedro Peláez
 

symfony-bundle worker-bundle

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

image

treehouselabs/worker-bundle

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  • Wednesday, October 11, 2017
  • by fieg
  • Repository
  • 7 Watchers
  • 12 Stars
  • 15,449 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 6 Forks
  • 3 Open issues
  • 7 Versions
  • 9 % Grown

The README.md

Deprecated & archived

This bundle is no longer maintained. It will still work with Symfony versions ^2.8|^3.0|^4.0 and is archived here to not break existing applications using it. However it will not get maintenance updates or even security fixes., (*1)

If you need queue/worker functionality in your project, there are far better solutions right now to look at:, (*2)

  • https://github.com/symfony/messenger/
  • https://github.com/php-enqueue/enqueue-dev

Previous readme below 👇, (*3)


Worker bundle

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score, (*4)

A Symfony bundle that adds worker functionality to your project, using Beanstalkd as the message queue., (*5)

Installation

For this process, we assume you have a Beanstalk server up and running., (*6)

Install via Composer:, (*7)

$ composer require treehouselabs/worker-bundle

Enable the bundle:, (*8)

# app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...

            new TreeHouse\WorkerBundle\TreeHouseWorkerBundle(),
        ];

        // ...
    }

    // ...
}

Configuration

Define a queue and you're good to go:, (*9)

# app/config/config.yml

tree_house_worker:
  queue:
    server: localhost

The bundle also supports the PheanstalkBundle, if you're using that:, (*10)

# app/config/config.yml

tree_house_worker:
  pheanstalk: leezy.pheanstalk

Basic Usage

The bundle creates a QueueManager service, which you can use to manage jobs. The manager has services registered to execute specific tasks, called executors. An executor receives a job from the QueueManager and processes it., (*11)

Defining executors

First you need to register an executor, and tag it as such:, (*12)

# src/AppBundle/Executor/HelloWorldExecutor.php

use TreeHouse\WorkerBundle\Executor\AbstractExecutor;

class HelloWorldExecutor extends AbstractExecutor
{
    public function getName()
    {
        return 'hello.world';
    }

    public function configurePayload(OptionsResolver $resolver)
    {
        $resolver->setRequired(0);
    }

    public function execute(array $payload)
    {
        $name = array_shift($payload);

        # process stuff here, in this example we just print something
        echo 'Hello, ' . $name;

        return true;
    }
}
# app/config/services.yml
app.executor.hello_world:
  class: AppBundle/Executor/HelloWorldExecutor
  tags:
    - { name: tree_house.worker.executor }

Scheduling jobs

Now you can add jobs, either via code or using the worker:schedule command:, (*13)

In your application's code:, (*14)

$queueManager = $container->get('tree_house.worker.queue_manager');
$queueManager->add('hello.world', ['Peter']);

Using the command:, (*15)

php app/console worker:schedule hello.world Peter

Working jobs

A worker can now receive and process these jobs via the console:, (*16)

php app/console worker:run

# prints:
# Working hello.world with payload ["Peter"]
# Hello, Peter
# Completed job in 1ms with result: true

You can run workers by adding them to your crontab, creating a Supervisor program for it, or whatever your preferred method is., (*17)

Documentation

  1. Message queues & workers
  2. The QueueManager
  3. Executors
  4. Working jobs

Security

If you discover any security related issues, please email dev@treehouse.nl instead of using the issue tracker., (*18)

License

The MIT License (MIT). Please see License File for more information., (*19)

Credits

The Versions

11/10 2017

dev-master

9999999-dev

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd

11/10 2017

v1.2.1

1.2.1.0

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd

17/02 2016

v1.2.0

1.2.0.0

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd

28/10 2015

v1.1.1

1.1.1.0

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd

27/08 2015

v1.1.0

1.1.0.0

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd

07/08 2015

v1.0.1

1.0.1.0

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd

24/04 2015

v1.0.0

1.0.0.0

Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue

  Sources   Download

MIT

The Requires

 

The Development Requires

beanstalk worker beanstalkd