0

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);
}

1 Answer 1

0

If you are sure that your execution do not produce programming errors, the problem may come from the fact that Drupal only executes queue items when running Cron. Taking into account that Drupal Cron is limited by time and PHP memory, your queue items may not be fully processed in a single Cron run.

You can refer to this issue I created some time ago about a very similar problem.

In short, I solved it by processing queue items every X minutes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.