2017 © Pedro PelĂĄez
 

library command-queue

Library providing command queue

image

gendoria/command-queue

Library providing command queue

  • Monday, October 24, 2016
  • by TiS
  • Repository
  • 2 Watchers
  • 0 Stars
  • 304 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Command queue library

This library delivers basic interfaces and tools to create command backend delegation system, which allows passing tasks for processing by scallable backend worker infrastructure., (*1)

Build Status Scrutinizer Code Quality Code Coverage Downloads Latest Stable Version, (*2)

Library created in cooperation with Isobar Poland., (*3)

Isobar Poland, (*4)

Installation

Step 1: Download the library

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*5)

$ composer require gendoria/command-queue "~0.2.0"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*6)

Usage

This library provides building blocks to create command queue system, where you delgate your tasks to a pools of backend workers for further processing., (*7)

By itself, it does have a simple implementation of 'direct' command queue, where commands are not sent, but executed locally by a driver., (*8)

The simplest example of working queue chain using direct processing driver is below., (*9)

use Gendoria\CommandQueue\Command\CommandInterface;
use Gendoria\CommandQueue\CommandProcessor\CommandProcessorInterface;
use Gendoria\CommandQueue\ProcessorFactory\ProcessorFactory;
use Gendoria\CommandQueue\SendDriver\DirectProcessingDriver;
use Psr\Log\LoggerInterface;

class SimpleCommand implements CommandInterface
{
    public $testData;

    public function __construct($testData)
    {
        $this->testData = $testData;
    }
}

class SimpleProcessor implements CommandProcessorInterface
{
    /**
     *
     * @var LoggerInterface
     */
    private $logger;

    /**
     * Process command.
     * 
     * @param SimpleCommand $command
     */
    public function process(CommandInterface $command)
    {
        echo "Command class: ".get_class($command)."\n";
        echo "Command payload: ".$command->testData."\n";
        echo "\n";
    }

    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function supports(CommandInterface $command)
    {
        return $command instanceof SimpleCommand;
    }

}

$simpleProcessor = new SimpleProcessor();

$processorFactory = new ProcessorFactory();
$processorFactory->registerProcessorForCommand(SimpleCommand::class, $simpleProcessor);

$driver = new DirectProcessingDriver($processorFactory);

for ($k = 0; $k < 5; $k++) {
    $command = new SimpleCommand("Test ".($k+1));
    $driver->send($command);
    sleep(1);
}

You can find this example in examples/direct.php file. If you run it, you should see the following output:, (*10)

$ php example/direct.php
Command class: SimpleCommand
Command payload: Test 1

Command class: SimpleCommand
Command payload: Test 2

Command class: SimpleCommand
Command payload: Test 3

Command class: SimpleCommand
Command payload: Test 4

Command class: SimpleCommand
Command payload: Test 5

Direct processing driver is not very usable in real world application, as it does not delegate any tasks. But you can use it at an early stage of your application development, when you know, for tasks you want to delegate to backend processing at later date., (*11)

The Versions

24/10 2016

dev-master

9999999-dev

Library providing command queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gendoria
by Tomasz StruczyƄski

24/10 2016

0.2.1

0.2.1.0

Library providing command queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gendoria
by Tomasz StruczyƄski

24/10 2016

0.2.0

0.2.0.0

Library providing command queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gendoria
by Tomasz StruczyƄski

12/10 2016

0.1.0

0.1.0.0

Library providing command queue

  Sources   Download

MIT

The Requires

 

by Gendoria
by Tomasz StruczyƄski