Skip to content
Open
Changes from all 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
25 changes: 7 additions & 18 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\Push\AdapterPushHandler;
use Yiisoft\Queue\Middleware\Push\PushHandlerInterface;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareConfig;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\Push\SynchronousPushHandler;
Expand Down Expand Up @@ -48,16 +47,13 @@ public function __construct(
mixed ...$middlewareDefinitions,
) {
$this->name = StringNormalizer::normalize($name);
$this->dispatcher = (new PushMiddlewareDispatcher(
$middlewareConfig->middlewareFactory,
$middlewareConfig->commonMiddlewareDefinitions,
$this->createFinalPushHandler(),
))->withMiddlewaresAdded($middlewareDefinitions);
}

public function __clone()
{
$this->dispatcher = $this->dispatcher->withFinishHandler($this->createFinalPushHandler());
$this->dispatcher = new PushMiddlewareDispatcher(
middlewareFactory: $middlewareConfig->middlewareFactory,
middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions],
finishHandler: $this->isSynchronous()
? new SynchronousPushHandler($this->worker, $this)
: new AdapterPushHandler($this->adapter),
);
}

public function getName(): string
Expand Down Expand Up @@ -157,13 +153,6 @@ private function handle(MessageInterface $message): bool
return $this->loop->canContinue();
}

private function createFinalPushHandler(): PushHandlerInterface
{
return $this->isSynchronous()
? new SynchronousPushHandler($this->worker, $this)
: new AdapterPushHandler($this->adapter);
}

/**
* @psalm-assert-if-false !null $this->adapter
*/
Expand Down
Loading