.. include:: /Includes.rst.txt .. _queue-callbacks: =============== Queue callbacks =============== .. versionadded:: 14.0.0 Callbacks implement `AOE\Crawler\Queue\Interface\QueueCallbackInterface`, see :ref:`upgrade-queue-callbacks`. Besides URLs, the queue can hold callbacks: instead of crawling a URL, the worker calls a class of your extension. This is useful for work that should run in the background with the crawler, e.g. crawling external files. The result is stored with the queue entry and shown in the :guilabel:`Crawler log`. Implement the callback ====================== A callback implements `AOE\Crawler\Queue\Interface\QueueCallbackInterface`. It is a service, so it gets its dependencies by constructor injection: .. code-block:: php :caption: EXT:my_extension/Classes/Crawler/ReindexFileCallback.php fileIndexer->reindex((int) $parameters['fileUid']); } } The return value is stored JSON encoded as the result of the queue entry. With `autoconfigure: true` in the :file:`Configuration/Services.yaml` of your extension, which is the default, the callback is registered automatically. Classes that are not services are created with `GeneralUtility::makeInstance()`, without constructor arguments. Add the callback to the queue ============================= Add a queue entry with `AOE\Crawler\Queue\QueueEntryWriter::addCallback()`. Inject the `QueueEntryWriter` into your own service: .. code-block:: php :caption: EXT:my_extension/Classes/Service/FileQueue.php queueEntryWriter->addCallback( ReindexFileCallback::class, ['fileUid' => $fileUid], $pageId, ); } } `addCallback()` takes these arguments: `$callbackClassName` The class implementing `QueueCallbackInterface`. `$parameters` Handed over to `execute()`. They are stored JSON encoded, so they must be JSON encodable. `$pageId` The page the queue entry is shown with in the :guilabel:`Crawler log`, `0` by default. `$scheduled` The Unix timestamp to execute the callback at, `0` (the default) for now. `$setId` The set the queue entry belongs to, `0` by default. Give several queue entries the same set id to show them together in the :guilabel:`Crawler log`. The queue entry is dispatched to the message bus like a URL, and processed by the worker, see :ref:`upgrade-message-bus`.