2017 © Pedro Peláez
 

library queue

Tomahawk Queue

image

tomahawk/queue

Tomahawk Queue

  • Tuesday, May 9, 2017
  • by tomgrohl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Tomahawk Queue

A nice and simple PHP Worker Queue library, (*1)

Requirements

  • PHP 7.0 +
  • pcntl extension.
  • posix extension.

Installation

You can install Tomahawk Queue using composer:, (*2)

composer require tomahawk/queue, (*3)

1. Setup configuration

First you need to create a new file called tomahawk.xml, (*4)

You will need to configure the following things:, (*5)

  • Storage directory - for logs and pid files
  • Bootstrap file (optional) - Allows you to add event listeners and extend storage
  • Your workers

Below is an example:, (*6)


<tomahawk
    storage="./storage"
    bootstrap="./queue-bootstrap.php">

    <workers>
        <worker pidkey="emails" name="Emails" queues="emails" />
    </workers>

</tomahawk>

2. Create Bootstrap file

Bootstrap example file, (*7)

<?php

use Tomahawk\Queue\Application;
use Tomahawk\Queue\Storage\StorageInterface;
use Tomahawk\Queue\Storage\RedisStorage;
use Predis\Client;
use Pimple\Container;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * Get the Autoloader
 */
require_once(__DIR__.'/vendor/autoload.php');

/**
 * Set Default Timezone
 */

date_default_timezone_set('Europe/London');

// Get the container
$container = Application::getContainer();

// Set storage for jobs
$container[StorageInterface::class] = function(Container $c) {
    $client = new Client([
         'scheme' => 'tcp',
         'host'   => '10.0.0.1',
         'port'   => 6379,
    ]);
    return new RedisStorage($client);
};

$eventDispatcher = $container[EventDispatcherInterface::class];

// Add events
$eventDispatcher->addListener(\Tomahawk\Queue\JobEvents::PROCESSED, function(\Tomahawk\Queue\Event\PreProcessEvent $event) {
    // Log to a file
});

$container[EventDispatcherInterface::class];

Using the CLI

Create a new worker

./bin/tomahawk-queue work emails emails --daemon, (*8)

Queue a new job to worker

./bin/tomahawk-queue queue emails JobClass {"id":"1"}, (*9)

List running workers

./bin/tomahawk-queue list, (*10)

Stop a running worker

./bin/tomahawk-queue stop emails, (*11)

Load and run all workers defined in configuration file

./bin/tomahawk-queue load, (*12)

Using the Queue Manager

If you have your works setup on a different VM or server you can still push jobs onto the queue using the Queue Manager., (*13)

Below is an example of how to do this, (*14)

```php <?php, (*15)

use Predis\Client; use Tomahawk\Queue\Manager; use Tomahawk\Queue\Storage\RedisStorage;, (*16)

$client = new Client([ 'scheme' => 'tcp', 'host' => '10.0.0.1', 'port' => 6379, ]); $storage = new RedisStorage($client);, (*17)

$manager = new Manager($storage);, (*18)

$arguments = [ 'email' => '...', 'subject' => '...', ];, (*19)

$manager->queue('queue_email', 'JobClass', $arguments); ```, (*20)

License

Tomahawk Queue is open-sourced software licensed under the MIT license, (*21)

The Versions

09/05 2017

dev-master

9999999-dev

Tomahawk Queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tom Ellis

queue worker

09/05 2017

0.2.0

0.2.0.0

Tomahawk Queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tom Ellis

queue worker

27/03 2017

0.1.3

0.1.3.0

Tomahawk Queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tom Ellis

queue worker

24/03 2017

0.1.2

0.1.2.0

Tomahawk Queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tom Ellis

queue worker

24/03 2017

0.1.1

0.1.1.0

Tomahawk Queue

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tom Ellis

queue worker

24/03 2017