Skip to content

Commit

Permalink
Merge pull request #19 from Daynnnnn/master
Browse files Browse the repository at this point in the history
Send SQS worker exceptions to defined log channel
  • Loading branch information
mnapoli authored Nov 14, 2020
2 parents 81e2fe0 + 9e98a4f commit 4a264c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Queue/LaravelSqsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bref\Event\Sqs\SqsEvent;
use Bref\Event\Sqs\SqsHandler;
use Illuminate\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Queue\Events\JobExceptionOccurred;
use Illuminate\Queue\Events\JobProcessed;
Expand All @@ -27,12 +28,14 @@ class LaravelSqsHandler extends SqsHandler
private $sqs;
/** @var Dispatcher */
private $events;
/** @var ExceptionHandler */
private $exceptions;
/** @var string */
private $connectionName;
/** @var string */
private $queue;

public function __construct(Container $container, Dispatcher $events, string $connection, string $queue)
public function __construct(Container $container, Dispatcher $events, ExceptionHandler $exceptions, string $connection, string $queue)
{
$this->container = $container;
/** @var QueueManager $queueManager */
Expand All @@ -43,6 +46,7 @@ public function __construct(Container $container, Dispatcher $events, string $co
}
$this->sqs = $queueConnector->getSqs();
$this->events = $events;
$this->exceptions = $exceptions;
$this->connectionName = $connection;
$this->queue = $queue;
}
Expand Down Expand Up @@ -88,8 +92,12 @@ private function process(string $connectionName, SqsJob $job): void

$this->raiseAfterJobEvent($connectionName, $job);
} catch (Throwable $e) {
// Fire off an exception event
$this->raiseExceptionOccurredJobEvent($connectionName, $job, $e);

// Report exception to defined log channel
$this->exceptions->report($e);

// Rethrow the exception to let SQS handle it
throw $e;
}
Expand Down

0 comments on commit 4a264c1

Please sign in to comment.