I am retrieving remote data by clicking an update button. I want to make it automatic. I read many articles about it but I didn't find a good example for using hook_cron_queue_info in my module. can anybody help me?
1 Answer
You can look at the example code shown in the documentation from hook_cron_queue_info(), which still needs an explanation on how it is used.
function hook_cron_queue_info() {
$queues['aggregator_feeds'] = array(
'worker callback' => 'aggregator_refresh',
'time' => 60,
);
return $queues;
}
The code show is actually the implementation of hook_cron_queue_info()
made from the Aggregator module. (See aggregator_cron_queue_info().)
"aggregator_feeds" is the name of a Drupal queue that is filled with items that need to be processed; "aggregator_refresh" is the name of a function that will be called when Drupal executes cron tasks, once for each item contained in the "aggregator_feeds" Drupal queue. aggregator_refresh() gets the item taken from that Drupal queue as first parameter.
The question you would ask at this point is: When are the Drupal queue items added to the queue?
The Aggregator module does that in its hook_cron()
implementation, but any function could add items to a Drupal queue, including other hooks (with the exception of hook_cron_queue_info()
and similar hooks*), form submission handlers, page callbacks, or any function called from those functions.
* By "similar hooks" I mean all those hooks that return information, and that are not invoked to handle an event or after/before an event occurred/occurs (as in the case of hook_node_delete()). In the list of "similar hooks," I would add, for example:
-
your answer made clear many things for me including the steps which happen in whole story. thanks a lot Commented Apr 9, 2013 at 19:26
$function = 'itunesdec_batch_update_apps'; $_SESSION['http_request_count'] = 0; // reset counter for debug information. $batch = $function(); batch_set($batch);
this is what i use in my hook_form_submit. I want to do this b a cron automatically so that user won't be forced to do this job.