Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.31 KB

File metadata and controls

38 lines (29 loc) · 1.31 KB

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):

$logger = $DIContainer->get(\Psr\Log\LoggerInterface::class);

$worker = $DIContainer->get(\Yiisoft\Queue\Worker\WorkerInterface::class);
$loop = $DIContainer->get(\Yiisoft\Queue\Cli\LoopInterface::class);
$pushMiddlewareConfig = $DIContainer->get(
    \Yiisoft\Queue\Middleware\Push\PushMiddlewareConfig::class
);

$queue = new Yiisoft\Queue\Queue(
    $worker,
    $loop,
    $logger,
    $pushMiddlewareConfig,
);

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.