Skip to content

Commit

Permalink
move MessageTest.php to Unit
Browse files Browse the repository at this point in the history
  • Loading branch information
TalismanFR committed Dec 9, 2024
1 parent da403f7 commit 69bef4c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
final class Adapter implements AdapterInterface
{
public function __construct(
private QueueProviderInterface $provider,
private QueueProviderInterface $provider,
private MessageSerializerInterface $serializer,
private LoopInterface $loop,
private int $timeout = 3
) {
private LoopInterface $loop,
private int $timeout = 3
)
{
}

public function runExisting(callable $handlerCallback): void
Expand Down Expand Up @@ -66,15 +67,18 @@ public function push(MessageInterface $message): MessageInterface

public function subscribe(callable $handlerCallback): void
{
while ($this->loop->canContinue()) {
$continue = true;
while ($continue) {
$message = $this->reserve();
if (null === $message) {
$continue = $this->loop->canContinue();
continue;
}

$result = $handlerCallback($message);
if ($result) {
$this->provider->delete((string) $message->getId());
$this->provider->delete((string) $message->getId());
if (!$result) {
$continue = false;
}
}
}
Expand All @@ -99,4 +103,9 @@ private function reserve(): ?IdEnvelope

return $envelope;
}

public function getChannelName(): string
{
return $this->provider->getChannelName();
}
}
8 changes: 7 additions & 1 deletion src/QueueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class QueueProvider implements QueueProviderInterface
public function __construct(
private \Redis $redis, //redis connection,
private string $channelName = self::DEFAULT_CHANNEL_NAME
) {
)
{
}

/**
Expand Down Expand Up @@ -145,4 +146,9 @@ private function checkConnection(): void
throw new NotConnectedRedisException('Redis is not connected.');
}
}

public function getChannelName(): string
{
return $this->channelName;
}
}
2 changes: 2 additions & 0 deletions src/QueueProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public function existInWaiting(int $id): bool;
public function existInReserved(int $id): bool;

public function withChannelName(string $channelName): self;

public function getChannelName(): string;
}

0 comments on commit 69bef4c

Please sign in to comment.