Example: Queue

  1. drupal
    1. 8
    2. 7

Demonstrating the Queue API

The Queue API provides a traditional FIFO (first-in-first-out) queue, but also provides the concepts of:

  • "Creating" a queued item, which means inserting it into a queue.
  • "Claiming" a queued item, which essentially means requesting the next item from the queue and holding a lock on that item for a specified period of time.
  • "Releasing" an item, which means giving up a claim but leaving the item in the queue.
  • "Deleting" an item, which means finally removing it from the queue.

This example demonstrates only basic queue functionality, and will use the default queue implementation, which is SystemQueue, managed using persistent database storage.

Further resources include the limited documentation and Batch vs Queue Presentation slides by John VanDyk and session video.

Functions & methods

queue_example_add_remove_formProvides an interface to add items to the queue, to retrieve (claim) an item from the head of the queue, and to claim and delete. Also allows the user to run cron manually, so that claimed items can be released.
queue_example_add_remove_form_claimSubmit function for the "claim" button. Claims (retrieves) an item from the queue and reports the results.
queue_example_add_remove_form_clear_queueSubmit handler for clearing/deleting the queue.
queue_example_add_remove_form_deleteSubmit function for "Claim and delete" button.
queue_example_add_remove_form_insertSubmit function for the insert-into-queue button.
queue_example_add_remove_form_run_cronSubmit function for "run cron" button.
queue_example_menuImplements hook_menu().
queue_example_retrieve_queueRetrieves the queue from the database for display purposes only.
queue_example_themeImplements hook_theme().
theme_queue_itemsThemes the queue display.

examples/queue_example/queue_example.module, line 8