Skip to content

Commit

Permalink
fixing merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Kirk committed Jan 23, 2015
2 parents 2ca0c19 + 9f70222 commit 5cfa081
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The bundle should be installed through composer.
```json
{
"require": {
"uecode/qpush-bundle": "~1.4.0",
"uecode/qpush-bundle": "~2.0.0",
}
}
```
Expand Down
5 changes: 3 additions & 2 deletions docs/aws-provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ credentials in your configuration.
uecode_qpush:
providers:
aws:
my_provider:
driver: aws
key: <aws key>
secret: <aws secret>
region: us-east-1
queues:
my_queue_name:
provider: aws
provider: my_provider
options:
push_notifications: true
subscribers:
Expand Down
11 changes: 10 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,24 @@ A working configuration would look like the following
logging_enabled: true
providers:
aws:
driver: aws #optional for providers named 'aws' or 'ironmq'
key: YOUR_AWS_KEY_HERE
secret: YOUR_AWS_SECRET_HERE
region: YOUR_AWS_REGION_HERE
another_aws_provider:
driver: aws #required for named providers
key: YOUR_AWS_KEY_HERE
secret: YOUR_AWS_SECRET_HERE
region: YOUR_AWS_REGION_HERE
ironmq:
driver: aws #optional for providers named 'aws' or 'ironmq'
token: YOUR_IRONMQ_TOKEN_HERE
project_id: YOUR_IRONMQ_PROJECT_ID_HERE
in_band:
driver: sync
queues:
my_queue_key:
provider: ironmq #or aws or sync
provider: ironmq #or aws or in_band or another_aws_provider
options:
queue_name: my_actual_queue_name
push_notifications: true
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The bundle should be installed through composer.
{
"require": {
"uecode/qpush-bundle": "~1.1",
"uecode/qpush-bundle": "~2.0.0",
}
}
Expand Down
7 changes: 4 additions & 3 deletions docs/iron-mq-provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ an account and have a project id.
testing and using this service extremely easy.

Just include your OAuth `token` and `project_id` in the configuration and set your
queue to use the `ironmq` provider.
queue to use a provider using the `ironmq` driver.

.. code-block:: yaml
#app/config.yml
uecode_qpush:
providers:
ironmq:
my_provider:
driver: ironmq
token: YOUR_TOKEN_HERE
project_id: YOUR_PROJECT_ID_HERE
host: YOUR_OPTIONAL_HOST_HERE
port: YOUR_OPTIONAL_PORT_HERE
version_id: YOUR_OPTIONAL_VERSION_HERE
queues:
my_queue_name:
provider: ironmq
provider: my_provider
options:
push_notifications: true
subscribers:
Expand Down
7 changes: 5 additions & 2 deletions docs/sync-provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ of queue-based code paths.
Configuration
^^^^^^^^^^^^^

To use the sync queue, set the ``provider`` of a given queue to ``sync``. No further
To designate a queue as synchronous, set the ``driver`` of its provider to ``sync``. No further
configuration is necessary.

.. code-block:: yaml
#app/config_dev.yml
uecode_qpush:
providers:
in_band:
driver: sync
queues:
my_queue_name:
provider: sync
provider: in_band
146 changes: 86 additions & 60 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,62 @@ public function getConfigTreeBuilder()

private function getProvidersNode()
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('providers');
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('providers');
$requirements = [
'aws' => ['key', 'secret'],
'ironmq' => ['token', 'project_id'],
'sync' => [],
];

$node
->children()
->arrayNode('aws')
->children()
->scalarNode('key')->end()
->scalarNode('secret')->end()
->scalarNode('region')
->defaultValue('us-east-1')
->end()
->useAttributeAsKey('name')
->prototype('array')
->treatNullLike([])
->children()
->enumNode('driver')
->isRequired()
->values(array_keys($requirements))
->end()
->end()
->arrayNode('ironmq')
->children()
->scalarNode('token')->end()
->scalarNode('project_id')->end()
->enumNode('host')
->defaultValue('mq-aws-us-east-1')
->values([
'mq-aws-us-east-1',
'mq-aws-eu-west-1',
'mq-rackspace-ord',
'mq-rackspace-lon'
])
->end()
->scalarNode('port')
->defaultValue('443')
->end()
->scalarNode('api_version')
->defaultValue(1)
->end()
// IronMQ
->scalarNode('token')->end()
->scalarNode('project_id')->end()
->enumNode('host')
->defaultValue('mq-aws-us-east-1')
->values([
'mq-aws-us-east-1',
'mq-aws-eu-west-1',
'mq-rackspace-ord',
'mq-rackspace-lon',
])
->end()
->scalarNode('port')
->defaultValue('443')
->end()
->scalarNode('api_version')
->defaultValue(1)
->end()
// AWS
->scalarNode('key')->end()
->scalarNode('secret')->end()
->scalarNode('region')
->defaultValue('us-east-1')
->end()
->end()

->validate()
->always()
->then(function (array $provider) use ($node, $requirements) {
foreach ($requirements[$provider['driver']] as $requirement) {
if (empty($provider[$requirement])) {
throw new \InvalidArgumentException(
sprintf('%s queue providers must have a %s; none provided', $provider['driver'], $requirement)
);
}
}

return $provider;
})
->end()
;

Expand Down Expand Up @@ -119,36 +140,41 @@ private function getQueuesNode()
->defaultFalse()
->info('Whether notifications are sent to the subscribers')
->end()
->scalarNode('notification_retries')
->defaultValue(3)
->info('How many attempts the Push Notifications are retried if the Subscriber returns an error')
->example(3)
->end()
->scalarNode('message_delay')
->defaultValue(0)
->info('How many seconds before messages are inititally visible in the Queue')
->example(0)
->end()
->scalarNode('message_timeout')
->defaultValue(30)
->info('How many seconds the Queue hides a message while its being processed')
->example(30)
->end()
->scalarNode('message_expiration')
->defaultValue(604800)
->info('How many seconds a message is kept in Queue, the default is 7 days (604800 seconds)')
->example(604800)
->end()
->scalarNode('messages_to_receive')
->defaultValue(1)
->info('Max amount of messages to receive at once - an event will be fired for each individually')
->example(1)
->end()
->scalarNode('receive_wait_time')
->defaultValue(3)
->info('How many seconds to Long Poll when requesting messages - if supported')
->example(3)
->end()
->scalarNode('notification_retries')
->defaultValue(3)
->info('How many attempts the Push Notifications are retried if the Subscriber returns an error')
->example(3)
->end()
->scalarNode('notification_retry_delay')
->defaultValue(60)
->info('Delay between each Push Notification retry in seconds')
->example(3)
->end()
->scalarNode('message_delay')
->defaultValue(0)
->info('How many seconds before messages are inititally visible in the Queue')
->example(0)
->end()
->scalarNode('message_timeout')
->defaultValue(30)
->info('How many seconds the Queue hides a message while its being processed')
->example(30)
->end()
->scalarNode('message_expiration')
->defaultValue(604800)
->info('How many seconds a message is kept in Queue, the default is 7 days (604800 seconds)')
->example(604800)
->end()
->scalarNode('messages_to_receive')
->defaultValue(1)
->info('Max amount of messages to receive at once - an event will be fired for each individually')
->example(1)
->end()
->scalarNode('receive_wait_time')
->defaultValue(3)
->info('How many seconds to Long Poll when requesting messages - if supported')
->example(3)
->end()
->append($this->getSubscribersNode())
->end()
->end()
Expand Down
34 changes: 21 additions & 13 deletions src/DependencyInjection/UecodeQPushExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,21 @@ public function load(array $configs, ContainerBuilder $container)
$class = null;
$client = null;

switch ($provider) {
switch ($config['providers'][$provider]['driver']) {
case 'aws':
$class = $container->getParameter('uecode_qpush.provider.aws');
$client = $this->createAwsClient(
$config['providers'][$provider],
$container
$container,
$provider
);
break;
case 'ironmq':
$class = $container->getParameter('uecode_qpush.provider.ironmq');
$client = $this->createIronMQClient(
$config['providers'][$provider],
$container
$container,
$provider
);
break;
case 'sync':
Expand Down Expand Up @@ -116,12 +118,15 @@ public function load(array $configs, ContainerBuilder $container)
*
* @param array $config A Configuration array for the client
* @param ContainerBuilder $container The container
* @param string $name The provider key
*
* return Reference
* @return Reference
*/
private function createAwsClient($config, ContainerBuilder $container)
private function createAwsClient($config, ContainerBuilder $container, $name)
{
if (!$container->hasDefinition('uecode_qpush.provider.aws')) {
$service = sprintf('uecode_qpush.provider.%s', $name);

if (!$container->hasDefinition($service)) {

if (!class_exists('Aws\Common\Aws')) {
throw new \RuntimeException(
Expand All @@ -140,24 +145,27 @@ private function createAwsClient($config, ContainerBuilder $container)
]
]);

$container->setDefinition('uecode_qpush.provider.aws', $aws)
$container->setDefinition($service, $aws)
->setPublic(false);
}

return new Reference('uecode_qpush.provider.aws');
return new Reference($service);
}

/**
* Creates a definition for the IronMQ provider
*
* @param array $config A Configuration array for the provider
* @param ContainerBuilder $container The container
* @param string $name The provider key
*
* return Reference
* @return Reference
*/
private function createIronMQClient($config, ContainerBuilder $container)
private function createIronMQClient($config, ContainerBuilder $container, $name)
{
if (!$container->hasDefinition('uecode_qpush.provider.ironmq')) {
$service = sprintf('uecode_qpush.provider.%s', $name);

if (!$container->hasDefinition($service)) {

if (!class_exists('IronMQ')) {
throw new \RuntimeException(
Expand All @@ -176,11 +184,11 @@ private function createIronMQClient($config, ContainerBuilder $container)
]
]);

$container->setDefinition('uecode_qpush.provider.ironmq', $ironmq)
$container->setDefinition($service, $ironmq)
->setPublic(false);
}

return new Reference('uecode_qpush.provider.ironmq');
return new Reference($service);
}

private function createSyncClient()
Expand Down
1 change: 1 addition & 0 deletions src/Provider/IronMqProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function create()
$params = [
'push_type' => 'multicast',
'retries' => $this->options['notification_retries'],
'retry_delay' => $this->options['notification_retry_delay'],
'subscribers' => []
];

Expand Down
12 changes: 12 additions & 0 deletions tests/DependencyInjection/UecodeQPushExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ public function testConfiguration()
$this->container->compile();

$this->assertTrue($this->container->has('uecode_qpush'));

$this->assertTrue($this->container->has('uecode_qpush.test_aws'));
$this->assertTrue($this->container->has('uecode_qpush.test_secondary_aws'));
$this->assertNotSame(
$this->container->get('uecode_qpush.test_aws'),
$this->container->get('uecode_qpush.test_secondary_aws')
);

$this->assertTrue($this->container->has('uecode_qpush.test_ironmq'));
$this->assertTrue($this->container->has('uecode_qpush.test_secondary_ironmq'));
$this->assertNotSame(
$this->container->get('uecode_qpush.test_ironmq'),
$this->container->get('uecode_qpush.test_secondary_ironmq')
);
}
}
Loading

0 comments on commit 5cfa081

Please sign in to comment.