2017 © Pedro Peláez
 

symfony-bundle periodic-queue-driver-bundle

A bundle for running symfony background tasks with doctrine as the driver

image

mcfedr/periodic-queue-driver-bundle

A bundle for running symfony background tasks with doctrine as the driver

  • Thursday, April 5, 2018
  • by mcfedr
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6,759 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 1 Forks
  • 0 Open issues
  • 13 Versions
  • 22 % Grown

The README.md

Periodic Queue Driver Bundle

A driver for Queue Manager Bundle that uses runs jobs periodically., (*1)

This driver doesn't run jobs, it requires another driver to actually process jobs., (*2)

Latest Stable Version License Build Status, (*3)

Usage

There is no runner daemon for this driver as it just plugs into other drivers. Use it by putting jobs into this driver with the period option., (*4)

Install

Composer

composer require mcfedr/periodic-queue-driver-bundle

AppKernel

Include the bundle in your AppKernel, (*5)

public function registerBundles()
{
    $bundles = [
        ...
        new Mcfedr\QueueManagerBundle\McfedrQueueManagerBundle(),
        new Mcfedr\PeriodicQueueDriverBundle\McfedrPeriodicQueueDriverBundle(),

Config

With this bundle installed you can setup your queue manager config similar to this:, (*6)

mcfedr_queue_manager:
    managers:
        periodic:
            driver: periodic
            options:
                default_manager: delay
                default_manager_options: []

This will create a QueueManager service named "mcfedr_queue_manager.periodic", (*7)

  • default_manager - Default job processor, must support delayed jobs, for example Doctrine Delay
  • default_manager_options - Default options to pass to job processor put

Options to QueueManager::put

  • period - The average number of seconds between job runs
  • manager - Use a different job processor for this job
  • manager_options - Options to pass to the processors put method

Explanation

Commands

There are two commands that can be used to investigate how well spread jobs will. A simple way to visualize is to pipe into feedgnuplot., (*8)

rand-add uses a naive implementation of just adding a random number of seconds to get the time for the next run:, (*9)

./tests/console test:distribution:rand-add -v | feedgnuplot --histogram 0 --binwidth 60 --hardcopy "rand-add.png" --exit

Graph of rand-add, (*10)

periodic uses the bundle implementation:, (*11)

./tests/console test:distribution:periodic -v | feedgnuplot --histogram 0 --binwidth 60 --hardcopy "periodic.png" --exit

Graph of periodic, (*12)

Job Token

There is job_tokens argument which can help with job uniqueness., (*13)

Usage example, (*14)

When put new periodic job, you get PeriodicJob object., (*15)

    $periodicJob = $this->manager->put('some_service', [
        'some_argument' => 'some_value',
    ], [
        'period' => 'some_seconds',
    ], 'periodic');

You can do $periodicJob->getToken() of it and store the token for job execution, (*16)

While execution, (*17)

 public function execute(array $arguments)
    {
        // Get the stored token
        ...

        if ($storedToken != $arguments['job_tokens']['token']) {
            throw new InvalidTokenException();
        }

        ...

        $storedToken = ($arguments['job_tokens']['next_token']);

        // Save stored token for next execition.
    }

Each job execution new token is generated so if some job duplication will appear only one will be executed and other jobs will fail, (*18)

The Versions

05/04 2018

dev-master

9999999-dev

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

20/03 2018

1.4.0

1.4.0.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

20/03 2018

dev-symfony-4

dev-symfony-4

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

03/11 2017

1.3.0

1.3.0.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

02/10 2017

1.2.1

1.2.1.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

29/09 2017

1.2.0

1.2.0.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

29/09 2017

dev-periodic_job_token

dev-periodic_job_token

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

28/09 2017

1.1.0

1.1.0.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

19/07 2017

1.0.4

1.0.4.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

19/07 2017

1.0.3

1.0.3.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

19/07 2017

1.0.2

1.0.2.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

19/07 2017

1.0.1

1.0.1.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule

13/02 2017

1.0.0

1.0.0.0

A bundle for running symfony background tasks with doctrine as the driver

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fred Cox

task doctrine queue job schedule