![]() ![]() ![]() Provided in this section, is an example of a batch function to publish a node. A Cron QueueWorker plugin src/Plugin/QueueWorker/ExQueue01.php that will process each item in the queue. You would not want to have a long running piece of code but you could implement the Drupal queue API or some other batch processing API so that all you do is check for completion status in the batch function code. GetData() - Get external data and insert the data in the queue 'exqueue_import'.ĭeleteTheQueue() - Delete all item in the queue.Ģ. A controller class src/Controller/ExQueueController.php with its corresponding route in and two main methods: Next, when Cron runs,, we'll create a node page with a QueueWorker plugin for each item in the queue. In this example module we'll generate a queue with a controller, importing the title and the description tags form the Drupal Planet RSS file. Remember that the Drupal cron is 'poor man’s cron', as it depends on page requests for its execution even if there is a way to execute it with a linux crontab. This is also a more reliable method because it uses fewer resources and it is independent of any page request. Today we'll create the queue with a controller and process it with a QueueWorker plugin when cron runs or manually with Drupal Console.Ĭreating the queue with a controller has the advantage of allowing us to use an external crontab (e.g., a Linux crontab), so we won't need Drupal’s cron at all to run the controller, allowing us to launch it when we need it. ![]() As a batch process claiming each item of the queue in a service or in a controller As a batch process also with QueueWorker plugin but extending a base plugin As a cron process with a QueueWorker plugin To process the queue, we also have different options: There are several ways to create a queue: Items can be added to the queue by passing an arbitrary data object toDrupalCoreQueueQueueInterface::createItem(). To do so, we are going to put some tasks or data in a queue (create the queue) and later we will process those tasks with a QueueWorker plugin (process the queue), usually triggered by cron. Before a queue can be used it needs to be created byDrupalCoreQueueQueueInterface::createQueue(). Queues are particularly important when we need to stash some tasks for later processing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |