Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 31
Replace SynchronousAdapter with SynchronousPushHandler#270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c9e25dbee6e8c30a1022b6ba2134c89194db1ebd7b0e17a9c884ea350eeb85f1cbb04e62521e77f8c23eb55ab080f4ac4102bf1969908377bacf4102b0fa1ed0e84b4e94de012479f7cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Synchronous Mode | ||
| Run tasks synchronously in the same process. Useful for: | ||
| - developing and debugging an application; | ||
| - writing tests; | ||
| - production setups where the application is built around `QueueInterface` from day one but | ||
| doesn't have an external broker yet — you can switch to a real adapter later without touching | ||
| the call sites. | ||
| To enable it, create the queue instance without an adapter (the `adapter` argument defaults to `null`): | ||
| ```php | ||
| $logger = $DIContainer->get(\Psr\Log\LoggerInterface::class); | ||
| $worker = $DIContainer->get(\Yiisoft\Queue\Worker\WorkerInterface::class); | ||
| $loop = $DIContainer->get(\Yiisoft\Queue\Cli\LoopInterface::class); | ||
| $pushMiddlewareDispatcher = $DIContainer->get( | ||
| \Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher::class | ||
| ); | ||
| $queue = new Yiisoft\Queue\Queue( | ||
| $worker, | ||
| $loop, | ||
| $logger, | ||
| $pushMiddlewareDispatcher, | ||
| ); | ||
| ``` | ||
| In synchronous mode every message passed to `push()` is processed immediately by the worker. | ||
| The value returned from `push()` is the message after push-middlewares — without an `IdEnvelope`, | ||
| since no adapter is involved to assign an ID. | ||
| Limitations: | ||
| - `run()` does nothing and returns `0`. | ||
| - `listen()` logs an info message and returns without listening. | ||
| - `status()` always returns `MessageStatus::NOT_FOUND` — there is no message storage to track IDs. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
| namespace Yiisoft\Queue\Middleware\Push; | ||
| use Yiisoft\Queue\Message\MessageInterface; | ||
| use Yiisoft\Queue\QueueInterface; | ||
| use Yiisoft\Queue\Worker\WorkerInterface; | ||
| /** | ||
| * @internal | ||
| */ | ||
| final class SynchronousPushHandler implements MessageHandlerPushInterface | ||
| { | ||
| public function __construct( | ||
| private readonly WorkerInterface $worker, | ||
| private readonly QueueInterface $queue, | ||
| ) {} | ||
| public function handlePush(MessageInterface $message): MessageInterface | ||
| { | ||
| $this->worker->process($message, $this->queue); | ||
| return $message; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine but we need a separate way of knowing if the adapter doesn't support status tracking. Probably in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#272