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
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.
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