Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/Debug/QueueDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Yiisoft\Queue\Debug;

use BackedEnum;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\JobStatus;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface;
Expand Down Expand Up @@ -45,11 +43,6 @@ public function listen(): void
$this->queue->listen();
}

public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static
{
return new self($this->queue->withAdapter($adapter, $queueName), $this->collector);
}

public function getName(): string
{
return $this->queue->getName();
Expand Down

This file was deleted.

11 changes: 5 additions & 6 deletions src/Middleware/Push/AdapterPushHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

namespace Yiisoft\Queue\Middleware\Push;

use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException;

/**
* @internal
*/
final class AdapterPushHandler implements MessageHandlerPushInterface
{
public function handlePush(PushRequest $request): PushRequest
{
if (($adapter = $request->getAdapter()) === null) {
throw new AdapterNotConfiguredException();
}
return $request->withMessage($adapter->push($request->getMessage()));
return $request->withMessage(
$request->getAdapter()->push(
$request->getMessage(),
),
);
}
}
7 changes: 5 additions & 2 deletions src/Middleware/Push/PushRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

final class PushRequest
{
public function __construct(private MessageInterface $message, private ?AdapterInterface $adapter) {}
public function __construct(
private MessageInterface $message,
private AdapterInterface $adapter,
) {}

public function getMessage(): MessageInterface
{
return $this->message;
}

public function getAdapter(): ?AdapterInterface
public function getAdapter(): AdapterInterface
{
return $this->adapter;
}
Expand Down
113 changes: 0 additions & 113 deletions src/Provider/AdapterFactoryQueueProvider.php

This file was deleted.

30 changes: 1 addition & 29 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Psr\Log\LoggerInterface;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\Push\AdapterPushHandler;
use Yiisoft\Queue\Middleware\Push\MessageHandlerPushInterface;
Expand All @@ -33,8 +32,8 @@ public function __construct(
private readonly LoopInterface $loop,
private readonly LoggerInterface $logger,
private readonly PushMiddlewareDispatcher $pushMiddlewareDispatcher,
private readonly AdapterInterface $adapter,
Comment thread
samdark marked this conversation as resolved.
Outdated
string|BackedEnum $name = QueueProviderInterface::DEFAULT_QUEUE,
private ?AdapterInterface $adapter = null,
MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions,
Comment thread
vjik marked this conversation as resolved.
) {
$this->name = StringNormalizer::normalize($name);
Expand All @@ -51,7 +50,6 @@ public function push(
MessageInterface $message,
MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions,
): MessageInterface {
$this->checkAdapter();
$this->logger->debug(
'Preparing to push message with handler name "{handlerName}".',
['handlerName' => $message->getHandlerName()],
Expand All @@ -74,8 +72,6 @@ public function push(

public function run(int $max = 0): int
{
$this->checkAdapter();

$this->logger->debug('Start processing queue messages.');
$count = 0;

Expand All @@ -100,30 +96,16 @@ public function run(int $max = 0): int

public function listen(): void
{
$this->checkAdapter();

$this->logger->info('Start listening to the queue.');
$this->adapter->subscribe(fn(MessageInterface $message) => $this->handle($message));
$this->logger->info('Finish listening to the queue.');
}

public function status(string|int $id): JobStatus
{
$this->checkAdapter();
return $this->adapter->status($id);
}

public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static
{
$new = clone $this;
$new->adapter = $adapter;
if ($queueName !== null) {
$new->name = StringNormalizer::normalize($queueName);
}

return $new;
}

public function withMiddlewares(MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions): self
{
$instance = clone $this;
Expand All @@ -147,16 +129,6 @@ private function handle(MessageInterface $message): bool
return $this->loop->canContinue();
}

/**
* @psalm-assert AdapterInterface $this->adapter
*/
private function checkAdapter(): void
{
if ($this->adapter === null) {
throw new AdapterNotConfiguredException();
}
}

private function createPushHandler(MiddlewarePushInterface|callable|array|string ...$middlewares): MessageHandlerPushInterface
{
return new class (
Expand Down
10 changes: 0 additions & 10 deletions src/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Yiisoft\Queue;

use BackedEnum;
use InvalidArgumentException;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface;

Expand Down Expand Up @@ -41,14 +39,6 @@ public function listen(): void;
*/
public function status(string|int $id): JobStatus;

/**
* @param AdapterInterface $adapter Adapter to use.
* @param string|BackedEnum|null $queueName Queue name to use.
*
* @return static A new queue with the given adapter and queue name.
*/
public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static;

/**
* Returns the logical name of the queue.
*/
Expand Down
29 changes: 4 additions & 25 deletions stubs/StubQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace Yiisoft\Queue\Stubs;

use BackedEnum;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\JobStatus;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface;
use Yiisoft\Queue\QueueInterface;
use Yiisoft\Queue\StringNormalizer;

/**
* Stub queue that does nothing. Job status is always "done".
Expand All @@ -24,13 +22,12 @@ final class StubQueue implements QueueInterface
*/
public function __construct(
private ?AdapterInterface $adapter = null,
Comment thread
samdark marked this conversation as resolved.
Outdated
private string $name = 'default'
) {
}
private string $name = 'default',
) {}

public function push(
MessageInterface $message,
string|array|callable|MiddlewarePushInterface ...$middlewareDefinitions
string|array|callable|MiddlewarePushInterface ...$middlewareDefinitions,
): MessageInterface {
return $message;
}
Expand All @@ -40,9 +37,7 @@ public function run(int $max = 0): int
return 0;
}

public function listen(): void
{
}
public function listen(): void {}

public function status(int|string $id): JobStatus
{
Expand All @@ -57,22 +52,6 @@ public function getAdapter(): ?AdapterInterface
return $this->adapter;
}

/**
* @param T $adapter
* @return static<T>
*/
public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static
{
$new = clone $this;
$new->adapter = $adapter;

if ($queueName !== null) {
$new->name = StringNormalizer::normalize($queueName);
}

return $new;
}

public function getName(): string
{
return $this->name;
Expand Down
Loading
Loading