bupy7/zf-queue

Queue module for Zend Framework 3.

1.0.3 2020-02-11 17:03 UTC

This package is auto-updated.

Last update: 2020-09-11 18:12:26 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status Coverage Status

Abstract queue module for Zend Framework 3. Module contains only abstract layers to create their own integrations using this module.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require bupy7/zf-queue "*"

or add

"bupy7/zf-queue": "*"

to the require section of your composer.json file.

Integration

Ready integrations

Create their own integration

TODO

Usage

Create task

Let's create our first an example task for queue:

// YourModule/src/task/ExampleTask.php

namespace YourModule\Task;

use Bupy7\Queue\Task\TaskInterface;
use Zend\Stdlib\ParametersInterface;
use Chat\Service\ChatService;

class SendAccountTask implements TaskInterface
{
    /**
     * @var ChatService
     */
    protected $chatService;

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

    /**
     * @param ParametersInterface $params
     * - message (string)
     * @return bool
     */
    public function execute(ParametersInterface $params): bool
    {
        $this->chatService->send($params->get('message'));
        return true;
    }
}

Run task

After you need to register task to queue manager:

// YouModule/config/queue.config.php

namespace YourModule;

return [
    'queue_manager' => [
        'factories' => [
            Task\ExampleTask::class => \Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class,
        ],
    ],
];

Now, add queue.config.php to your config list:

// YourModule/src/YourModule.php

class Module
{
    public function getConfig(): array
    {
        return array_merge(
            
            // another config files
            
            require __DIR__ . '/../config/queue.config.php'
        );
    }
}

Add the task to queue

$container->get('Bupy7\Queue\Service\QueueService')->add('YourModule\Task\ExampleTask');

Run queue

$container->get('Bupy7\Queue\Service\QueueService')->run();

License

zf-queue is released under the BSD 3-Clause License.