Skip to content

Commit 658e01b

Browse files
committed
Update message-bus and use AmphpPostgresTransaction as TTransaction
1 parent 248ebcd commit 658e01b

File tree

3 files changed

+27
-83
lines changed

3 files changed

+27
-83
lines changed

composer.lock

Lines changed: 19 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PostgresStorage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Amp\Postgres\PostgresByteA;
88
use Amp\Postgres\PostgresLink;
9+
use Amp\Postgres\PostgresTransaction as AmphpPostgresTransaction;
910
use Thesis\MessageBus\Envelope;
1011
use Thesis\MessageBus\Persistence\Outbox;
1112
use Thesis\MessageBus\Persistence\OutboxDoesNotExist;
@@ -14,7 +15,7 @@
1415

1516
/**
1617
* @api
17-
* @implements StorageSetup<PostgresTransaction>
18+
* @implements StorageSetup<AmphpPostgresTransaction>
1819
*/
1920
final readonly class PostgresStorage implements StorageSetup
2021
{
@@ -44,7 +45,7 @@ public function setup(): void
4445
public function beginTransaction(): Transaction
4546
{
4647
return new PostgresTransaction(
47-
transaction: $this->connection->beginTransaction(),
48+
wrappedTransaction: $this->connection->beginTransaction(),
4849
outboxTable: $this->outboxTable,
4950
);
5051
}

src/PostgresTransaction.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414

1515
/**
1616
* @api
17+
* @implements Transaction<AmphpPostgresTransaction>
1718
*/
1819
final readonly class PostgresTransaction implements Transaction
1920
{
2021
/**
2122
* @param non-empty-string $outboxTable
2223
*/
2324
public function __construct(
24-
public AmphpPostgresTransaction $transaction,
25+
public AmphpPostgresTransaction $wrappedTransaction,
2526
private string $outboxTable,
2627
) {}
2728

2829
public function commit(Outbox $outbox): void
2930
{
3031
try {
31-
$result = $this->transaction->execute(
32+
$result = $this->wrappedTransaction->execute(
3233
<<<SQL
3334
insert into {$this->outboxTable} (endpoint, message_id, envelopes)
3435
values (?, ?, ?)
@@ -45,7 +46,7 @@ public function commit(Outbox $outbox): void
4546
throw new OutboxAlreadyExists();
4647
}
4748

48-
$this->transaction->commit();
49+
$this->wrappedTransaction->commit();
4950
} catch (SqlTransactionError $exception) {
5051
throw new TransactionClosed(previous: $exception);
5152
}
@@ -54,7 +55,7 @@ public function commit(Outbox $outbox): void
5455
public function rollback(): void
5556
{
5657
try {
57-
$this->transaction->rollback();
58+
$this->wrappedTransaction->rollback();
5859
} catch (SqlTransactionError $exception) {
5960
throw new TransactionClosed(previous: $exception);
6061
}

0 commit comments

Comments
 (0)