Playing With Drupal Queues

2 replies [Last post]
philipnorton42's picture
Offline
Joined: 04/04/2010

Just playing with the new Drupal 7 queues classes.

<?php
    // Get the queue, we call it EventQueue
    $queue = DrupalQueue::get('EventQueue', TRUE);

    // Print some info about the queue object
    echo '<pre>' . var_export($queue, true) . '</pre>';
    
    // Set up a data item
    $item = array('dataitem1' => 'something', 'qwe' => '123');
    echo '<pre>' . print_r($item, true) . '</pre>';

    // Insert into the queue
    $queue->createItem($item);

    // Find the number of items in queue
    echo '<pre>' . print_r($queue->numberOfItems(), true) . '</pre>';

    // Grab the next item in the queue
    $got_item = $queue->claimItem();

    // print some info about it
    echo '<pre>' . print_r($got_item, true) . '</pre>';

    // delete the item we got from the queue
    $queue->deleteItem($got_item);

    // Find out how many items are in our queue
    echo '<pre>' . print_r($queue->numberOfItems(), true) . '</pre>';

This prints out the following:

SystemQueue::__set_state(array(
   'name' => 'EventQueue',
))
Array
(
    [dataitem1] => something
    [qwe] => 123
)
2
stdClass Object
(
    [data] => Array
        (
            [dataitem1] => something
            [qwe] => 123
        )

    [item_id] => 41
)
1

Anonymous
I just have to say, after

I just have to say, after having read tons of information on the Queue API, this single page has helped me more than anything to quickly grasp exactly what's happening in a given queue. Thanks.

philipnorton42's picture
Offline
Joined: 04/04/2010
Thanks! I recently did a talk

Thanks! I recently did a talk on the Queues API, which I am currently typing up into a post. There is a lot of information to go through so it's taking me a while. Take a look at the slides for my talk.

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <h5> <h6> <pre> <span> <p> <br />
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.