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

Commit e66b937

Browse files
committed
Merge pull request #27 from juriansluiman/catch-aws-exception
Rethrow SQS exception
2 parents 874d1db + b0e14a0 commit e66b937

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.4.2
2+
3+
- SlmQueueSqs now rethrow SQS exceptions instead of silently reinserting the job without notice.
4+
15
# 0.4.1
26

37
- Fix a bug when batch pushing/batch deleting a multiple of 10 jobs into the queue.

src/SlmQueueSqs/Worker/SqsWorker.php

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

33
namespace SlmQueueSqs\Worker;
44

5+
use Aws\Sqs\Exception\SqsException;
56
use Exception;
67
use SlmQueue\Job\JobInterface;
78
use SlmQueue\Queue\QueueInterface;
@@ -31,6 +32,10 @@ public function processJob(JobInterface $job, QueueInterface $queue)
3132
$queue->delete($job);
3233

3334
return WorkerEvent::JOB_STATUS_SUCCESS;
35+
} catch (SqsException $sqsException) {
36+
// We want to retrigger SQS exception as they may include useful debugging information like lack of
37+
// permissions
38+
throw $sqsException;
3439
} catch (Exception $exception) {
3540
// Do nothing, the job will be reinserted automatically for another try
3641
return WorkerEvent::JOB_STATUS_FAILURE_RECOVERABLE;

tests/SlmQueueSqsTest/Worker/SqsWorkerTest.php

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

33
namespace SlmQueueSqsTest\Worker;
44

5+
use Aws\Sqs\Exception\SqsException;
56
use PHPUnit_Framework_TestCase as TestCase;
67
use SlmQueue\Worker\WorkerEvent;
78
use SlmQueueSqs\Worker\SqsWorker;
@@ -55,4 +56,19 @@ public function testDoNotDeleteJobOnFailure()
5556
$this->assertEquals(WorkerEvent::JOB_STATUS_FAILURE_RECOVERABLE, $status);
5657
}
5758

59+
public function testRethrowSqsException()
60+
{
61+
$this->setExpectedException('Aws\Sqs\Exception\SqsException');
62+
63+
$queue = $this->getMock('SlmQueueSqs\Queue\SqsQueueInterface');
64+
$job = $this->getMock('SlmQueue\Job\JobInterface');
65+
66+
$job->expects($this->once())
67+
->method('execute')
68+
->will($this->throwException(new SqsException()));
69+
70+
$queue->expects($this->never())->method('delete');
71+
72+
$this->worker->processJob($job, $queue);
73+
}
5874
}

0 commit comments

Comments
 (0)