zlikavac32/beanstalkd-lib-bundle

Bundle for zlikavac32/beanstalkd-lib

0.3.0 2020-04-11 01:19 UTC

This package is auto-updated.

Last update: 2024-11-11 14:31:39 UTC


README

Build Status

Bundle for zlikavac32/beanstalkd-lib

Table of contents

  1. Installation
  2. Configuration
  3. Usage
    1. Tube definition
    2. Runner definition
    3. Server controller
  4. Examples

Installation

Recommended installation is through Composer.

composer require zlikavac32/beanstalkd-lib-bundle

Bundle must be enabled in config/bundles.php.

return [
    /* ... */

    Zlikavac32\BeanstalkdLibBundle\BeanstalkdLibBundle::class => ['all' => true],

    /* ... */
]

Next add default configuration entry for beanstalkd_lib. For example, in config/services/beanstalkd_lib.yaml. Check Configuration section for more info.

beanstalkd_lib: ~

This library uses zlikavac32/nsb-decorators which requires custom autoloader in application entry points like bin/console.

use Zlikavac32\NSBDecorators\Proxy;

/* ... */

spl_autoload_register(Proxy::class.'::loadFQN');

For now, since proxied decorators are evaluated, container requires must not be inlined (container.dumper.inline_class_loader parameter must not exist or be set to false).

Async signals are also a requirement.

pcntl_async_signals(true);

Configuration

Default configuration looks like:

beanstalkd_lib:
    adapters:
        socket: Zlikavac32\BeanstalkdLib\Adapter\PHP\Socket\NativePHPSocket
        yaml_parser: Zlikavac32\BeanstalkdLib\Adapter\Symfony\Yaml\SymfonyYamlParser
    server:
        host: 127.0.0.1
        port: 11300

Custom adapters can be implemented for better integration with existing software.

Usage

This section explains how to use this bundle.

Tube definition

To use beanstalkd lib client, every managed tube must be configured.

tube.domain_tube: # keys value itself is not important to the bundle
    class: Zlikavac32\BeanstalkdLib\Client\TubeConfiguration\StaticTubeConfiguration
    arguments:
        $defaultDelay: 0
        $defaultPriority: 1024
        $defaultTimeToRun: 60
        $defaultTubePauseDelay: 86400
        $serializer: '@DomainSerializer'
    tags:
        - { name: tube_configuration, tube: brute_force_hash }

Tag tube_configuration collects tube configurations and links them with the client.

Optionally, one could also use linker tag to link with the serializer, as can be seen in the examples/full/container.yaml.

Runner definition

To define tube runner, we can use job_runner tag. This tag collects runners and links them with the job dispatcher.

Foo\Runner\SomeRunnerClass:
    tags:
        - { name: job_runner, tube: tube_for_this_runner }

Additional decorators can be applied either manually or through decorator tag, as can be seen in the examples/full/container.yaml.

To run existing runners, use bin/console worker:run.

Server controller

Simple REPL controller for the client is provided as bin/console worker:controller. It can be used also to run standalone commands.

Server controller demo

Features include:

  • list tubes
  • pause/unpause tubes
  • print stats (with optional refresh)
  • flush tube/tubes

To use pager in peek command, evironment variable PAGER must be set to a pager program. less is one such program whcih can be used directly like PAGER=less bin/console ... or exported somewhere.

For less, additional environment variable LESS that describes less arguments can be defined. For example, LESS='-F' PAGER=less bin/console can be used to skip paging if the whole text can be displayed on screen.

In Docker, -R should be used to display color escape sequences correctly.

Examples

You can see more examples with code comments in examples.