annaratings.blogg.se

Drupal queue api
Drupal queue api






drupal queue api

The hook is called whenever entity access is checked. Drupal comes with a hook, called hook_entity_access. Since we’re creating an audit log, it makes sense we get the information from the permission layer. “When” is simply a timestamp for the operation. “What” is the operation performed, so this could be any CRUD (Create, Read, Update, Delete) function, but it should also include on what entity it was performed.

drupal queue api

We’d need to log who, what and when for an audit log. Now that we have a logging channel for our audit log, we need to decide what to log. It’s good practice, as calls to the container using the \Drupal static are discouraged due to the best practices of inversion of control. We implement the ContainerFactoryPluginInterface to be able to add the logging channel to the worker class using dependency injection. In our example, we’ll create the audit log worker as follows. Place your queue worker class in the Plugin/QueueWorker directory for your module and define a QueueWorker annotation for it, and you will have both a worker and a queue. You add Queues using the annotation API, and they are considered plugins. In the following example, we’ll set up a Queue Worker to process an audit log, so we can keep an eye on what’s going on in our system. You could add a job to a queue every time something happened and then process that task in the background. Queue workers work on a task queue and handle each task in a single process.

drupal queue api

Queue workers are not cron, but cron can execute them.

DRUPAL QUEUE API HOW TO

Today’s core drupal still has the core-cron Drush command, and some documentation of how to best set it up exists. Over time, modules were created to make cron more maintainable, and Drush commands made the wget call obsolete. In the bad ole days of Drupal, we were stuck with hook_cron and a single wget call to cron.php with a so-called “secure key.” This post is not a “history of cron in Drupal” post. In my opinion queue workers are often overlooked and underutilized as a way of dealing with background tasks.








Drupal queue api