Entity Enqueue provides utility functions to enqueue entities to be processed later using Drupal's Queue API. It will not process any entity enqueued, you have to write the corresponding queue worker callback as always according the Queue API.
In addition to saving a few lines of code on Queue API calls each time you create a queue item, the most useful part comes from the provided matching Drush commands for each possible function.

Example

Code

  $data = array(
    'custom_queue_data_field' => 'foobar',
  );
  entity_enqueue_entity('nodes_to_export', 1234, 'node', $data);

Drush command

$ drush entity-enqueue nodes_to_export 1234 --type=node --data="{custom_queue_data_field:'foobar'}"

The enqueued item data payload that your worker callback will get is:

  $data = array(
    'entity_id' => 1234,
    'entity_type' => 'node',
    'custom_queue_data_field' => 'foobar',
  );

Enqueue entities resulting from an EntityFieldQuery

When you have a lot of entities to enqueue, it is more practical to run a query and enqueue the resulting items in batches. If you want to enqueue entities resulting from a query, use this code:

// Enqueue article nodes created before a certain date
$ts = [TIMESTAMP_BEFORE]

$efq = new EntityFieldQuery();
$efq->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'article')
  ->entityCondition('created', $ts, '<')
  ->propertyOrderBy('nid', 'DESC');
 
entity_enqueue_efq($efq, 'my-queue');

This will create a job in the entity_enqueue_efq built-in queue. Just make sure you process this queue and on each processing, it will populate the target queue with the entities resulting from the query.

Ideas & ToDo

  • Document functions/provide docblocks.
  • Allow to use tokens on custom data
  • Functions to enqueue a fully loaded object
  • entity_enqueue_multiple functions
  • Enqueue entities resulting from an EntityFieldQuery (see 'eeq_efq' branch)
  • Services integration
  • Actions integration
  • Views Bulk Operations integration

Project information

Releases