Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #64 from juriansluiman/options
Browse files Browse the repository at this point in the history
Add queues options
  • Loading branch information
Jurian Sluiman committed Jan 9, 2014
2 parents 674bacf + f90e4a2 commit 43a0324
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 46 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -210,18 +209,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()
{
Expand All @@ -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
Expand All @@ -251,17 +249,16 @@ 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
)
)
)
);
```


### Executing jobs

Once again, executing jobs is dependant on the queue system used. Therefore, please refer to either SlmQueueBeanstalkd,
Expand Down
14 changes: 7 additions & 7 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@

'slm_queue' => array(
/**
* Parameters for the worker
* Worker options
*/
'worker' => array(
'max_runs' => 100000,
'max_memory' => 100 * 1024 * 1024
),

/**
* Queue configuration
*/
'queues' => array(),

/**
* Job manager configuration
*/
Expand All @@ -27,10 +32,5 @@
* Queue manager configuration
*/
'queue_manager' => array(),

/**
* Queue configuration options
*/
'queues' => array(),
),
)
);
27 changes: 17 additions & 10 deletions config/slm_queue.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ return 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,
'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(),

/**
* Allow to configure dependencies for jobs that are pulled from any queue. This works like any other
Expand Down
1 change: 0 additions & 1 deletion src/SlmQueue/Worker/AbstractWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ abstract class AbstractWorker implements WorkerInterface, EventManagerAwareInter
*/
protected $options;


/**
* Constructor
*
Expand Down
26 changes: 8 additions & 18 deletions tests/SlmQueueTest/Options/WorkerOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@
namespace SlmQueueTest\Options;

use PHPUnit_Framework_TestCase as TestCase;
use SlmQueueTest\Util\ServiceManagerFactory;
use Zend\ServiceManager\ServiceManager;
use SlmQueue\Options\WorkerOptions;

class WorkerOptionsTest extends TestCase
{
/**
* @var ServiceManager
*/
protected $serviceManager;

public function setUp()
{
parent::setUp();
$this->serviceManager = ServiceManagerFactory::getServiceManager();
}

public function testCreateWorkerOptions()
public function testGettersAndSetters()
{
/** @var $workerOptions \SlmQueue\Options\WorkerOptions */
$workerOptions = $this->serviceManager->get('SlmQueue\Options\WorkerOptions');
$workerOptions = new WorkerOptions(array(
'max_runs' => 10,
'max_memory' => 1000
));

$this->assertInstanceOf('SlmQueue\Options\WorkerOptions', $workerOptions);
$this->assertEquals(100000, $workerOptions->getMaxRuns());
$this->assertEquals(104857600, $workerOptions->getMaxMemory());
$this->assertEquals(10, $workerOptions->getMaxRuns());
$this->assertEquals(1000, $workerOptions->getMaxMemory());
}
}

0 comments on commit 43a0324

Please sign in to comment.