I'm trying to use Drupal Queue and Cron to execute a task. In the following example I:
- select all the users
- create an item in the queue for each of them
- define the function that has to be run for the items of the queue
What happen is that at some point the system stops running the queue and the only way to start again the process is to kill it. (I'm using Ultimate cron to controll Cron processes).
I understood that after some time the system should stop the script and start it again at the following cron job. Am I wrong?
Here there is the code:
function mymodule_cron() {
$sql = db_query("select u.uid, u.mail FROM {users} u WHERE u.status=1");
$queue = DrupalQueue::get("testlogging");
$number_of_rows = $sql->rowCount();
if ($number_of_rows > 0) {
foreach ($sql as $record) {
$queue->createItem($record);
}
}
}
function mymodule_cron_queue_info() {
$queues = array();
$queues['testlogging'] = array (
'worker callback' => 'log_user',
'time' => 300,
);
return $queues;
}
function log_user($record) {
watchdog('MyModule', 'queue info: uid = ' . $record->uid . " " . $record->mail);
sleep(2);
}