2017 © Pedro Peláez
 

symfony-bundle queue-system-bundle

Queue System Bundle - Jobs and Workers

image

bernardosecades/queue-system-bundle

Queue System Bundle - Jobs and Workers

  • Saturday, October 22, 2016
  • by bernardosecades
  • Repository
  • 1 Watchers
  • 0 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

QueueSytem for Symfony

Simple queue system based on Redis, (*1)

Installing/Configuring

Version

  • Use alias of dev-master for last version.

Installing

``` bash wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make, (*2)


## Installing bundle You have to add require line into you composer.json file ``` yml "require": { ... "bernardosecades/queue-system-bundle": "dev-master" },

Then you have to use composer to update your project dependencies, (*3)

``` bash php composer.phar update, (*4)


And register the bundle in your AppKernel.php file ``` php return array( // ... new BernardoSecades\QueueSystemBundle\QueueSystemBundle(), // ... );

Configuration

In the current version, all conections are localhost:6379, but as soon as posible connections will be configurable, the same for events. You need to configure all. By default jms serializer has the value 'Json'. In next version you will can implement custom serializer., (*5)

``` yml queue_system: # Queues definition queues: images: "queue:mail" api: "queue:api", (*6)

# Server configuration. By default, these values
server:
    redis:
        host: 127.0.0.1
        port: 6379
        database: ~

Jobs and Queues --------------- Each queue you define in config.yml will create a queue service, for example if you define queue 'queue:api' you can access to queue like a service with `$this->getContainer()->get('queue_system.queue_api')`, example: `Producer` ```php ... use BernardoSecades\QueueSystemBundle\Job\MessageDataJob; ... /** @var \BernardoSecades\QueueSystemBundle\Queue\Queue $queue */ $queue = $this->getContainer()->get('queue_system.queue_api'); $message = new MessageDataJob('queue_system.api_job', ['user_id' => 13567]); $queue->enqueue($message);

In this example you should create a service API job extending of BernardoSecades\QueueSystemBundle\Job\JobAbstract, where you will need implement the method handle() and getDicName(), the first parameter of object MessageDataJob is the service name of your custom job., (*7)

class ApiJob extends JobAbstract
{
    /**
     * Name service in your dependency injection container
     *
     * {@inheritdoc}
     */
    public function getDicName()
    {
        return 'queue_system.api_job';
    }

    /**
     * {@inheritdoc}
     */
    public function handle()
    {
        $arguments = $this->getArguments();
        syslog(0, sprintf('Executing method handle with argument user_id: %d', $arguments['user_id']));
        ...
        // do more things
    }
}

Worker

This bundle include a worker command to consume jobs from queue saved in redis., (*8)

Example to consume jobs from queue queue:api you should execute the next command:, (*9)

./app/console queue-system:worker queue:api, (*10)

The command have options like:, (*11)

  • --worker-max-jobs=WORKER-MAX-JOBS Number of jobs to process [default: 0]
  • --worker-tries-process-job=WORKER-TRIES-PROCESS-JOB Number of retries to process a job [default: 0]
  • --worker-max-memory=WORKER-MAX-MEMORY Memory limit (Mb) [default: 0]
  • --worker-sleep=WORKER-SLEEP In addition, you may specify the number of seconds to wait before polling for new jobs: [default: 0]

Todo

  • More tests
  • Include event distpatcher.
  • Include log system in worker command.
  • Custom serializer.
  • Fix code style to have compatibility with symfony style.
  • Include external services to check quality code and fix possible issues.
  • Improve the documentation and include example how set up worker in supervisord.

The Versions

22/10 2016

dev-master

9999999-dev

Queue System Bundle - Jobs and Workers

  Sources   Download

MIT

The Requires

 

The Development Requires

redis bundle symfony queue job worker