Skip to content

Commit eef2d69

Browse files
committed
Merge branch 'sdufel-fix-aws-exception'
2 parents ce57ddf + b496957 commit eef2d69

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/vendor
33
/docs/_build
44
/coverage
5+
.idea

src/Provider/AwsProvider.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace Uecode\Bundle\QPushBundle\Provider;
2424

2525
use Aws\Sns\SnsClient;
26+
use Aws\Sns\Exception\NotFoundException;
2627
use Aws\Sqs\SqsClient;
2728
use Aws\Sqs\Exception\SqsException;
2829

@@ -73,10 +74,11 @@ public function __construct($name, array $options, $client, Cache $cache, Logger
7374
$this->options = $options;
7475
$this->cache = $cache;
7576
$this->logger = $logger;
77+
7678
// get() method used for sdk v2, create methods for v3
7779
$useGet = method_exists($client, 'get');
78-
$this->sqs = $useGet ? $client->get('Sqs') : $client->createSqs();
79-
$this->sns = $useGet ? $client->get('Sns') : $client->createSns();
80+
$this->sqs = $useGet ? $client->get('Sqs') : $client->createSqs();
81+
$this->sns = $useGet ? $client->get('Sns') : $client->createSns();
8082
}
8183

8284
public function getProvider()
@@ -315,13 +317,17 @@ public function queueExists()
315317
return true;
316318
}
317319

318-
$result = $this->sqs->getQueueUrl([
319-
'QueueName' => $this->getNameWithPrefix()
320-
]);
320+
try {
321+
$result = $this->sqs->getQueueUrl([
322+
'QueueName' => $this->getNameWithPrefix()
323+
]);
321324

322-
if($this->queueUrl = $result->get('QueueUrl')) {
323-
return true;
324-
}
325+
if ($this->queueUrl = $result->get('QueueUrl')) {
326+
$this->cache->save($key, $this->queueUrl);
327+
328+
return true;
329+
}
330+
} catch (SqsException $e) {}
325331

326332
return false;
327333
}
@@ -413,6 +419,24 @@ public function topicExists()
413419
return true;
414420
}
415421

422+
if (!empty($this->queueUrl)) {
423+
$queueArn = $this->sqs->getQueueArn($this->queueUrl);
424+
$topicArn = str_replace('sqs', 'sns', $queueArn);
425+
426+
try {
427+
$this->sns->getTopicAttributes([
428+
'TopicArn' => $topicArn
429+
]);
430+
} catch (NotFoundException $e) {
431+
return false;
432+
}
433+
434+
$this->topicArn = $topicArn;
435+
$this->cache->save($key, $this->topicArn);
436+
437+
return true;
438+
}
439+
416440
return false;
417441
}
418442

tests/MockClient/SnsMockClient.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace Uecode\Bundle\QPushBundle\Tests\MockClient;
2424

25+
use Aws\Sns\Exception\NotFoundException;
2526
use Doctrine\Common\Collections\ArrayCollection;
2627

2728
/**
@@ -50,6 +51,19 @@ public function createTopic(array $args)
5051
]);
5152
}
5253

54+
public function getTopicAttributes(array $args)
55+
{
56+
if ($args['TopicArn'] == null) {
57+
throw new NotFoundException;
58+
}
59+
60+
return new ArrayCollection([
61+
'Attributes' => [
62+
'TopicArn' => 'long_topic_arn_string'
63+
]
64+
]);
65+
}
66+
5367
public function listSubscriptionsByTopic(array $args)
5468
{
5569
return new ArrayCollection([

0 commit comments

Comments
 (0)