From fae8629f6a613f1414bd1e410248e0a2f6dfecdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 1 Jan 2014 18:58:14 +0100 Subject: [PATCH 1/8] Add options --- CHANGELOG.md | 1 + config/module.config.php | 26 +++---- config/slm_queue.local.php.dist | 31 +++++--- ...nsFactory.php => ModuleOptionsFactory.php} | 6 +- src/SlmQueue/Options/ModuleOptions.php | 71 +++++++++++++++++++ .../Options/ModuleOptionsTest.php | 28 ++++++++ .../Options/WorkerOptionsTest.php | 31 -------- 7 files changed, 137 insertions(+), 57 deletions(-) rename src/SlmQueue/Factory/{WorkerOptionsFactory.php => ModuleOptionsFactory.php} (65%) create mode 100644 src/SlmQueue/Options/ModuleOptions.php create mode 100644 tests/SlmQueueTest/Options/ModuleOptionsTest.php delete mode 100644 tests/SlmQueueTest/Options/WorkerOptionsTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 70cca06..559cc56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.3.0 - BC: raised dependency to ZF 2.2 +- BC: options for SlmQueue have been wrapped inside a new "options" key - BC: composer package has been changed from "juriansluiman/slm-queue" to "slm/queue". Remember to update your `composer.json` file! - BC: AbstractJob constructor is now gone. It simplifies injecting dependencies as you do not need to remember diff --git a/config/module.config.php b/config/module.config.php index 1aa8a47..9afe19f 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -4,18 +4,25 @@ 'service_manager' => array( 'factories' => array( 'SlmQueue\Job\JobPluginManager' => 'SlmQueue\Factory\JobPluginManagerFactory', - 'SlmQueue\Options\WorkerOptions' => 'SlmQueue\Factory\WorkerOptionsFactory', + 'SlmQueue\Options\ModuleOptions' => 'SlmQueue\Factory\ModuleOptionsFactory', 'SlmQueue\Queue\QueuePluginManager' => 'SlmQueue\Factory\QueuePluginManagerFactory' ), ), 'slm_queue' => array( - /** - * Parameters for the worker - */ - 'worker' => array( - 'max_runs' => 100000, - 'max_memory' => 100 * 1024 * 1024 + 'options' => array( + /** + * Parameters for the worker + */ + 'worker' => array( + 'max_runs' => 100000, + 'max_memory' => 100 * 1024 * 1024 + ), + + /** + * Queue configuration options + */ + 'queues' => array(), ), /** @@ -27,10 +34,5 @@ * Queue manager configuration */ 'queue_manager' => array(), - - /** - * Queue configuration options - */ - 'queues' => array(), ), ); diff --git a/config/slm_queue.local.php.dist b/config/slm_queue.local.php.dist index 05b859b..d952067 100644 --- a/config/slm_queue.local.php.dist +++ b/config/slm_queue.local.php.dist @@ -7,20 +7,29 @@ return array( 'slm_queue' => array( - /** - * Parameters for the worker. It defines some criterias that can be reached before the - * worker stops to process any other jobs - */ - 'worker' => array( + 'options' => array( /** - * Specify how many jobs can be processed by a worker until it stops (default to 100 000) + * Parameters for the worker. It defines some criterias that can be reached before the + * worker stops to process any other jobs */ - // 'max_runs' => 100000, + 'worker' => array( + /** + * Specify how many jobs can be processed by a worker until it stops (default to 100 000) + */ + // 'max_runs' => 100000, - /** - * Specifiy the max memory (in bytes) that can be used by the worker before it stops (default to 100 MB) - */ - // 'max_memory' => 100 * 1024 * 1024 + /** + * Specifiy the max memory (in bytes) that can be used by the worker before it stops (default to 100 MB) + */ + // 'max_memory' => 100 * 1024 * 1024 + ), + + /** + * Allow to configure a specific queue. + * + * Available options depends on the queue factory + */ + 'queues' => array() ), /** diff --git a/src/SlmQueue/Factory/WorkerOptionsFactory.php b/src/SlmQueue/Factory/ModuleOptionsFactory.php similarity index 65% rename from src/SlmQueue/Factory/WorkerOptionsFactory.php rename to src/SlmQueue/Factory/ModuleOptionsFactory.php index af97f97..23097f4 100644 --- a/src/SlmQueue/Factory/WorkerOptionsFactory.php +++ b/src/SlmQueue/Factory/ModuleOptionsFactory.php @@ -2,11 +2,11 @@ namespace SlmQueue\Factory; -use SlmQueue\Options\WorkerOptions; +use SlmQueue\Options\ModuleOptions; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class WorkerOptionsFactory implements FactoryInterface +class ModuleOptionsFactory implements FactoryInterface { /** * {@inheritDoc} @@ -14,6 +14,6 @@ class WorkerOptionsFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); - return new WorkerOptions($config['slm_queue']['worker']); + return new ModuleOptions($config['slm_queue']['options']); } } diff --git a/src/SlmQueue/Options/ModuleOptions.php b/src/SlmQueue/Options/ModuleOptions.php new file mode 100644 index 0000000..dd8d940 --- /dev/null +++ b/src/SlmQueue/Options/ModuleOptions.php @@ -0,0 +1,71 @@ +workerOptions = new WorkerOptions($workerOptions); + } + + /** + * @return WorkerOptions + */ + public function getWorker() + { + return $this->workerOptions; + } + + /** + * @param array $queuesOptions + */ + public function setQueues(array $queuesOptions) + { + $this->queuesOptions = $queuesOptions; + } + + /** + * @return array + */ + public function getQueues() + { + return $this->queuesOptions; + } +} diff --git a/tests/SlmQueueTest/Options/ModuleOptionsTest.php b/tests/SlmQueueTest/Options/ModuleOptionsTest.php new file mode 100644 index 0000000..ce8171e --- /dev/null +++ b/tests/SlmQueueTest/Options/ModuleOptionsTest.php @@ -0,0 +1,28 @@ + array( + 'max_runs' => 10, + 'max_memory' => 1000 + ), + 'queues' => array( + 'foo' => array() + ) + )); + + $this->assertInstanceOf('SlmQueue\Options\WorkerOptions', $moduleOptions->getWorker()); + $this->assertEquals(10, $moduleOptions->getWorker()->getMaxRuns()); + $this->assertEquals(1000, $moduleOptions->getWorker()->getMaxMemory()); + + $this->assertInternalType('array', $moduleOptions->getQueues()); + } +} diff --git a/tests/SlmQueueTest/Options/WorkerOptionsTest.php b/tests/SlmQueueTest/Options/WorkerOptionsTest.php deleted file mode 100644 index ad2a4e4..0000000 --- a/tests/SlmQueueTest/Options/WorkerOptionsTest.php +++ /dev/null @@ -1,31 +0,0 @@ -serviceManager = ServiceManagerFactory::getServiceManager(); - } - - public function testCreateWorkerOptions() - { - /** @var $workerOptions \SlmQueue\Options\WorkerOptions */ - $workerOptions = $this->serviceManager->get('SlmQueue\Options\WorkerOptions'); - - $this->assertInstanceOf('SlmQueue\Options\WorkerOptions', $workerOptions); - $this->assertEquals(100000, $workerOptions->getMaxRuns()); - $this->assertEquals(104857600, $workerOptions->getMaxMemory()); - } -} From b655ef847539b6600154a3d0bc060fc50e65278c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 1 Jan 2014 19:02:56 +0100 Subject: [PATCH 2/8] Add default value --- src/SlmQueue/Options/ModuleOptions.php | 2 +- src/SlmQueue/Worker/AbstractWorker.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SlmQueue/Options/ModuleOptions.php b/src/SlmQueue/Options/ModuleOptions.php index dd8d940..28c26e3 100644 --- a/src/SlmQueue/Options/ModuleOptions.php +++ b/src/SlmQueue/Options/ModuleOptions.php @@ -35,7 +35,7 @@ class ModuleOptions extends AbstractOptions * * @var array */ - protected $queuesOptions; + protected $queuesOptions = array(); /** * @param array $workerOptions diff --git a/src/SlmQueue/Worker/AbstractWorker.php b/src/SlmQueue/Worker/AbstractWorker.php index b4f468d..659f0ad 100644 --- a/src/SlmQueue/Worker/AbstractWorker.php +++ b/src/SlmQueue/Worker/AbstractWorker.php @@ -36,7 +36,6 @@ abstract class AbstractWorker implements WorkerInterface, EventManagerAwareInter */ protected $options; - /** * Constructor * From 636eb87af3c02437002fc7af2d1f7481d7498461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 8 Jan 2014 14:14:41 +0100 Subject: [PATCH 3/8] Remove options key --- config/module.config.php | 26 ++++++------ ...cal.php.dist => slm_queue.global.php.dist} | 40 +++++++++---------- src/SlmQueue/Factory/ModuleOptionsFactory.php | 2 +- src/SlmQueue/Options/ModuleOptions.php | 7 ++++ 4 files changed, 39 insertions(+), 36 deletions(-) rename config/{slm_queue.local.php.dist => slm_queue.global.php.dist} (69%) diff --git a/config/module.config.php b/config/module.config.php index 9afe19f..f4253cf 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -10,21 +10,19 @@ ), 'slm_queue' => array( - 'options' => array( - /** - * Parameters for the worker - */ - 'worker' => array( - 'max_runs' => 100000, - 'max_memory' => 100 * 1024 * 1024 - ), - - /** - * Queue configuration options - */ - 'queues' => array(), + /** + * Worker options + */ + 'worker' => array( + 'max_runs' => 100000, + 'max_memory' => 100 * 1024 * 1024 ), + /** + * Queue configuration options + */ + 'queues' => array(), + /** * Job manager configuration */ @@ -34,5 +32,5 @@ * Queue manager configuration */ 'queue_manager' => array(), - ), + ) ); diff --git a/config/slm_queue.local.php.dist b/config/slm_queue.global.php.dist similarity index 69% rename from config/slm_queue.local.php.dist rename to config/slm_queue.global.php.dist index d952067..b678403 100644 --- a/config/slm_queue.local.php.dist +++ b/config/slm_queue.global.php.dist @@ -7,30 +7,28 @@ return array( 'slm_queue' => array( - 'options' => array( - /** - * Parameters for the worker. It defines some criterias that can be reached before the - * worker stops to process any other jobs - */ - 'worker' => array( - /** - * Specify how many jobs can be processed by a worker until it stops (default to 100 000) - */ - // 'max_runs' => 100000, - - /** - * Specifiy the max memory (in bytes) that can be used by the worker before it stops (default to 100 MB) - */ - // 'max_memory' => 100 * 1024 * 1024 - ), + /** + * Parameters for the worker. It defines some criterias that can be reached before the + * worker stops to process any other jobs + */ + 'worker' => array( + /** + * Specify how many jobs can be processed by a worker until it stops (default to 100 000) + */ + // 'max_runs' => 100000, /** - * Allow to configure a specific queue. - * - * Available options depends on the queue factory + * Specifiy the max memory (in bytes) that can be used by the worker before it stops (default to 100 MB) */ - 'queues' => array() - ), + // 'max_memory' => 100 * 1024 * 1024 + ), + + /** + * Allow to configure a specific queue. + * + * Available options depends on the queue factory + */ + 'queues' => array(), /** * Allow to configure dependencies for jobs that are pulled from any queue. This works like any other diff --git a/src/SlmQueue/Factory/ModuleOptionsFactory.php b/src/SlmQueue/Factory/ModuleOptionsFactory.php index 23097f4..71502da 100644 --- a/src/SlmQueue/Factory/ModuleOptionsFactory.php +++ b/src/SlmQueue/Factory/ModuleOptionsFactory.php @@ -14,6 +14,6 @@ class ModuleOptionsFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); - return new ModuleOptions($config['slm_queue']['options']); + return new ModuleOptions($config['slm_queue']); } } diff --git a/src/SlmQueue/Options/ModuleOptions.php b/src/SlmQueue/Options/ModuleOptions.php index 28c26e3..d0492a1 100644 --- a/src/SlmQueue/Options/ModuleOptions.php +++ b/src/SlmQueue/Options/ModuleOptions.php @@ -25,6 +25,13 @@ */ class ModuleOptions extends AbstractOptions { + /** + * Disable strict mode + * + * @var bool + */ + protected $__strictMode__ = false; + /** * @var WorkerOptions */ From f9b10d51f688b7f5b61c0c399ac311f15eb5cd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 8 Jan 2014 14:17:51 +0100 Subject: [PATCH 4/8] Fix doc --- README.md | 16 ++++++++-------- src/SlmQueue/Version.php | 11 ----------- 2 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 src/SlmQueue/Version.php diff --git a/README.md b/README.md index 8ea3f59..c8c7df8 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,12 @@ SlmQueue works with Composer. To install it, just add the following line into yo ```json "require": { - "slm/queue": ">=0.3" + "slm/queue": "0.3.*" } ``` Then, enable the module by adding `SlmQueue` in your `application.config.php` file. You may also want to configure -the module: just copy the `slm_queue.local.php.dist` (you can find this file in the `config` folder of SlmQueue) into +the module: just copy the `slm_queue.global.php.dist` (you can find this file in the `config` folder of SlmQueue) into your `config/autoload` folder, and override what you want. > SlmQueue is pretty useless by itself, as it is mainly interfaces and abstract classes. To make it really powerful, @@ -210,18 +210,18 @@ class EncodingJob extends AbstractJob implements QueueAwareInterface } ``` -If you want to avoid the boilerplate code, you can use the ProvidesQueue trait (only for PHP >=5.4): +If you want to avoid the boilerplate code, you can use the QueueAwareTrait trait (only for PHP >=5.4): ```php namespace Application\Job; use SlmQueue\Job\AbstractJob; -use SlmQueue\Queue\ProvidesQueue; +use SlmQueue\Queue\QueueAwareTrait; use SlmQueue\Queue\QueueAwareInterface; class EncodingJob extends AbstractJob implements QueueAwareInterface { - use ProvidesQueue; + use QueueAwareTrait; public function execute() { @@ -251,10 +251,10 @@ In both cases, adding a new queue is as simple as adding a new line in your `mod ```php return array( 'slm_queue' => array( - 'queues' => array( + 'queue_manager' => array( 'factories' => array( - 'encodingQueue' => 'SlmQueueBeanstalkd\Factory\TubeFactory' // This is the factory provided by - // SlmQueueBeanstalkd module + 'encodingQueue' => 'SlmQueueSqs\Factory\SqsQueueFactory' // This is the factory provided by + // SlmQueueSqs module ) ) ) diff --git a/src/SlmQueue/Version.php b/src/SlmQueue/Version.php deleted file mode 100644 index 91dbc99..0000000 --- a/src/SlmQueue/Version.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Wed, 8 Jan 2014 14:18:52 +0100 Subject: [PATCH 5/8] Fix conflicts --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index c8c7df8..ba6fc99 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,6 @@ Here, we simply specify the data of the job, then we get the queue manager (more that will store those jobs (in most queuing systems you can create as much queues as you want), and then we push it so that it can pe popped later. - ### Handling dependencies for jobs Often, your job will have dependencies. For instance, the EncodingJob may need an Encoder object to help encode @@ -172,7 +171,7 @@ return array( ); ``` -> Note: if you don't have any dependencies for your jobs, you DO NOT need to add all your jobs to the invokables` +> Note: if you don't have any dependencies for your jobs, you DO NOT need to add all your jobs to the `invokables` > list, because the JobPluginManager is configured in a way that it automatically adds any unknown classes to the > `invokables` list. @@ -230,7 +229,6 @@ class EncodingJob extends AbstractJob implements QueueAwareInterface } ``` - ### Adding queues The Job thing is pretty agnostic to any queue management systems. However, the queues are not. SlmQueue provides @@ -261,7 +259,6 @@ return array( ); ``` - ### Executing jobs Once again, executing jobs is dependant on the queue system used. Therefore, please refer to either SlmQueueBeanstalkd, From ab614161726e0b2a667305dd6d5950e8423ea7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 8 Jan 2014 16:55:49 +0100 Subject: [PATCH 6/8] Remove module options --- config/module.config.php | 4 +- ...nsFactory.php => WorkerOptionsFactory.php} | 6 +- src/SlmQueue/Options/ModuleOptions.php | 78 ------------------- .../Options/ModuleOptionsTest.php | 28 ------- .../Options/WorkerOptionsTest.php | 21 +++++ 5 files changed, 26 insertions(+), 111 deletions(-) rename src/SlmQueue/Factory/{ModuleOptionsFactory.php => WorkerOptionsFactory.php} (67%) delete mode 100644 src/SlmQueue/Options/ModuleOptions.php delete mode 100644 tests/SlmQueueTest/Options/ModuleOptionsTest.php create mode 100644 tests/SlmQueueTest/Options/WorkerOptionsTest.php diff --git a/config/module.config.php b/config/module.config.php index f4253cf..cc669bb 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -4,7 +4,7 @@ 'service_manager' => array( 'factories' => array( 'SlmQueue\Job\JobPluginManager' => 'SlmQueue\Factory\JobPluginManagerFactory', - 'SlmQueue\Options\ModuleOptions' => 'SlmQueue\Factory\ModuleOptionsFactory', + 'SlmQueue\Options\WorkerOptions' => 'SlmQueue\Factory\WorkerOptionsFactory', 'SlmQueue\Queue\QueuePluginManager' => 'SlmQueue\Factory\QueuePluginManagerFactory' ), ), @@ -19,7 +19,7 @@ ), /** - * Queue configuration options + * Queue configuration */ 'queues' => array(), diff --git a/src/SlmQueue/Factory/ModuleOptionsFactory.php b/src/SlmQueue/Factory/WorkerOptionsFactory.php similarity index 67% rename from src/SlmQueue/Factory/ModuleOptionsFactory.php rename to src/SlmQueue/Factory/WorkerOptionsFactory.php index 71502da..af8c1c8 100644 --- a/src/SlmQueue/Factory/ModuleOptionsFactory.php +++ b/src/SlmQueue/Factory/WorkerOptionsFactory.php @@ -2,11 +2,11 @@ namespace SlmQueue\Factory; -use SlmQueue\Options\ModuleOptions; +use SlmQueue\Options\WorkerOptions; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class ModuleOptionsFactory implements FactoryInterface +class WorkerOptionsFactory implements FactoryInterface { /** * {@inheritDoc} @@ -14,6 +14,6 @@ class ModuleOptionsFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); - return new ModuleOptions($config['slm_queue']); + return new WorkerOptions($config['slm_queue']); } } diff --git a/src/SlmQueue/Options/ModuleOptions.php b/src/SlmQueue/Options/ModuleOptions.php deleted file mode 100644 index d0492a1..0000000 --- a/src/SlmQueue/Options/ModuleOptions.php +++ /dev/null @@ -1,78 +0,0 @@ -workerOptions = new WorkerOptions($workerOptions); - } - - /** - * @return WorkerOptions - */ - public function getWorker() - { - return $this->workerOptions; - } - - /** - * @param array $queuesOptions - */ - public function setQueues(array $queuesOptions) - { - $this->queuesOptions = $queuesOptions; - } - - /** - * @return array - */ - public function getQueues() - { - return $this->queuesOptions; - } -} diff --git a/tests/SlmQueueTest/Options/ModuleOptionsTest.php b/tests/SlmQueueTest/Options/ModuleOptionsTest.php deleted file mode 100644 index ce8171e..0000000 --- a/tests/SlmQueueTest/Options/ModuleOptionsTest.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - 'max_runs' => 10, - 'max_memory' => 1000 - ), - 'queues' => array( - 'foo' => array() - ) - )); - - $this->assertInstanceOf('SlmQueue\Options\WorkerOptions', $moduleOptions->getWorker()); - $this->assertEquals(10, $moduleOptions->getWorker()->getMaxRuns()); - $this->assertEquals(1000, $moduleOptions->getWorker()->getMaxMemory()); - - $this->assertInternalType('array', $moduleOptions->getQueues()); - } -} diff --git a/tests/SlmQueueTest/Options/WorkerOptionsTest.php b/tests/SlmQueueTest/Options/WorkerOptionsTest.php new file mode 100644 index 0000000..c627f08 --- /dev/null +++ b/tests/SlmQueueTest/Options/WorkerOptionsTest.php @@ -0,0 +1,21 @@ + 10, + 'max_memory' => 1000 + )); + + $this->assertInstanceOf('SlmQueue\Options\WorkerOptions', $workerOptions); + $this->assertEquals(10, $workerOptions->getMaxRuns()); + $this->assertEquals(1000, $workerOptions->getMaxMemory()); + } +} From 20f1dcac03e5ead1b719ed54e95c8de9bb0beaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 8 Jan 2014 16:57:07 +0100 Subject: [PATCH 7/8] fix changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0b177..fba91b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # 0.3.0 - BC: raised dependency to ZF 2.2 -- BC: options for SlmQueue have been wrapped inside a new "options" key - BC: composer package has been changed from "juriansluiman/slm-queue" to "slm/queue". Remember to update your `composer.json` file! - BC: AbstractJob constructor is now gone. It simplifies injecting dependencies as you do not need to remember From f90e4a23c8dc9153ac88d49f6d6b43010e628d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 8 Jan 2014 17:15:27 +0100 Subject: [PATCH 8/8] Fix factory --- src/SlmQueue/Factory/WorkerOptionsFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SlmQueue/Factory/WorkerOptionsFactory.php b/src/SlmQueue/Factory/WorkerOptionsFactory.php index af8c1c8..af97f97 100644 --- a/src/SlmQueue/Factory/WorkerOptionsFactory.php +++ b/src/SlmQueue/Factory/WorkerOptionsFactory.php @@ -14,6 +14,6 @@ class WorkerOptionsFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); - return new WorkerOptions($config['slm_queue']); + return new WorkerOptions($config['slm_queue']['worker']); } }