Playing With Drupal Queues

3 posts / 0 new
Last post
philipnorton42's picture
Offline
Last seen: 1 day 14 hours ago
Joined: 04/04/2010 - 23:03
Playing With Drupal Queues

Just playing with the new Drupal 7 queues classes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
    // Get the queue, we call it EventQueue
    $queue = DrupalQueue::get('EventQueue', TRUE);
 
    // Print some info about the queue object
    var_dump($queue);
    
    // Set up a data item
    $item = array('dataitem1' => 'something', 'qwe' => '123');
    print_r($item);
 
    // Insert into the queue
    $queue->createItem($item);
 
    // Find the number of items in queue
    print_r($queue->numberOfItems());
 
    // Grab the next item in the queue
    $got_item = $queue->claimItem();
 
    // print some info about it
    print_r($got_item);
 
    // delete the item we got from the queue
    $queue->deleteItem($got_item);
 
    // Find out how many items are in our queue
    print_r($queue->numberOfItems());

This prints out the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 (not verified)

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
Last seen: 1 day 14 hours ago
Joined: 04/04/2010 - 23:03

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.