how to use hook_cron_queue_info in a custom module? 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?
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' =&gt; 'aggregator_refresh',
    'time' =&gt; 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:


hook_menu()
hook_entity_info()
hook_field_info()
hook_archiver_info()
hook_tokens_info()