From 11e9a37524f7307bbee6069088524a25b7917543 Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 6 Jan 2024 23:04:55 +0100 Subject: [PATCH] fix: connection name for used handler --- src/Handlers/BaseHandler.php | 4 +++- src/Handlers/DatabaseHandler.php | 8 ++++++++ src/Handlers/PredisHandler.php | 8 ++++++++ src/Handlers/RedisHandler.php | 8 ++++++++ tests/PredisHandlerTest.php | 4 ++-- tests/RedisHandlerTest.php | 4 ++-- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Handlers/BaseHandler.php b/src/Handlers/BaseHandler.php index 42547d1..6e29e45 100644 --- a/src/Handlers/BaseHandler.php +++ b/src/Handlers/BaseHandler.php @@ -30,6 +30,8 @@ abstract class BaseHandler protected QueueConfig $config; protected ?string $priority = null; + abstract public function name(): string; + abstract public function push(string $queue, string $job, array $data): bool; abstract public function pop(string $queue, array $priorities): ?QueueJob; @@ -144,7 +146,7 @@ protected function logFailed(QueueJob $queueJob, Throwable $err): bool "file: {$err->getFile()}:{$err->getLine()}"; $queueJobFailed = new QueueJobFailed([ - 'connection' => 'database', + 'connection' => $this->name(), 'queue' => $queueJob->queue, 'payload' => $queueJob->payload, 'priority' => $queueJob->priority, diff --git a/src/Handlers/DatabaseHandler.php b/src/Handlers/DatabaseHandler.php index 6c7d949..5c11279 100644 --- a/src/Handlers/DatabaseHandler.php +++ b/src/Handlers/DatabaseHandler.php @@ -33,6 +33,14 @@ public function __construct(protected QueueConfig $config) $this->jobModel = model(QueueJobModel::class, true, $connection); } + /** + * Name of the handler. + */ + public function name(): string + { + return 'database'; + } + /** * Add job to the queue. * diff --git a/src/Handlers/PredisHandler.php b/src/Handlers/PredisHandler.php index 0819d0f..c06c9d3 100644 --- a/src/Handlers/PredisHandler.php +++ b/src/Handlers/PredisHandler.php @@ -38,6 +38,14 @@ public function __construct(protected QueueConfig $config) } } + /** + * Name of the handler. + */ + public function name(): string + { + return 'predis'; + } + /** * Add job to the queue. */ diff --git a/src/Handlers/RedisHandler.php b/src/Handlers/RedisHandler.php index 953cd6e..6d4e537 100644 --- a/src/Handlers/RedisHandler.php +++ b/src/Handlers/RedisHandler.php @@ -53,6 +53,14 @@ public function __construct(protected QueueConfig $config) } } + /** + * Name of the handler. + */ + public function name(): string + { + return 'redis'; + } + /** * Add job to the queue. * diff --git a/tests/PredisHandlerTest.php b/tests/PredisHandlerTest.php index 471a273..4470295 100644 --- a/tests/PredisHandlerTest.php +++ b/tests/PredisHandlerTest.php @@ -182,7 +182,7 @@ public function testFailedAndKeepJob(): void $this->seeInDatabase('queue_jobs_failed', [ 'id' => 2, - 'connection' => 'database', + 'connection' => 'predis', 'queue' => 'queue1', ]); } @@ -206,7 +206,7 @@ public function testFailedAndDontKeepJob(): void $this->dontSeeInDatabase('queue_jobs_failed', [ 'id' => 2, - 'connection' => 'database', + 'connection' => 'predis', 'queue' => 'queue1', ]); } diff --git a/tests/RedisHandlerTest.php b/tests/RedisHandlerTest.php index daab676..e691197 100644 --- a/tests/RedisHandlerTest.php +++ b/tests/RedisHandlerTest.php @@ -166,7 +166,7 @@ public function testFailedAndKeepJob(): void $this->seeInDatabase('queue_jobs_failed', [ 'id' => 2, - 'connection' => 'database', + 'connection' => 'redis', 'queue' => 'queue1', ]); } @@ -187,7 +187,7 @@ public function testFailedAndDontKeepJob(): void $this->dontSeeInDatabase('queue_jobs_failed', [ 'id' => 2, - 'connection' => 'database', + 'connection' => 'redis', 'queue' => 'queue1', ]); }