Skip to content

Commit

Permalink
Merge pull request #36 from michalsn/connection-name
Browse files Browse the repository at this point in the history
fix: `connection` name for used handler
  • Loading branch information
michalsn committed Jan 9, 2024
2 parents 706ca99 + 11e9a37 commit 1482353
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/PredisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function testFailedAndKeepJob(): void

$this->seeInDatabase('queue_jobs_failed', [
'id' => 2,
'connection' => 'database',
'connection' => 'predis',
'queue' => 'queue1',
]);
}
Expand All @@ -206,7 +206,7 @@ public function testFailedAndDontKeepJob(): void

$this->dontSeeInDatabase('queue_jobs_failed', [
'id' => 2,
'connection' => 'database',
'connection' => 'predis',
'queue' => 'queue1',
]);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/RedisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testFailedAndKeepJob(): void

$this->seeInDatabase('queue_jobs_failed', [
'id' => 2,
'connection' => 'database',
'connection' => 'redis',
'queue' => 'queue1',
]);
}
Expand All @@ -187,7 +187,7 @@ public function testFailedAndDontKeepJob(): void

$this->dontSeeInDatabase('queue_jobs_failed', [
'id' => 2,
'connection' => 'database',
'connection' => 'redis',
'queue' => 'queue1',
]);
}
Expand Down

0 comments on commit 1482353

Please sign in to comment.