1

So this all starts when I hit my php memory limit, I know I can increase my php memory limit... but in order to get the process that I needed running I had to up my limit to 1026M... and I dont think that this is the right way to go.

My process needs to run using cron, so I first looked to batch processing... its very usefull and works well, except when implemented with cron.

I know see that the right path is to use the d7 backport of drupal_queues.

I would put up some code, but what I am really trying to understand is the logic behind setting up and processing a queue using drupal_queues and cron.

So far this is what I got:

I set up hook_queue_info:

function mymodule_cron_queue_info() {
  $queue['mymodule_queue'] = array(
      'worker callback' => '_mymodule_queue_worker',
      );
  return $queue;
}

I setup hook_queue_worker($item)

function _mymodule_queue_worker($item) {
  $acc_id = $item['acc_id'];
  //Collect list of relevant campaign ID's
  $campaignNIDs = mymodule_get_campaignNIDs($acc_id);
  dpm($campaignNIDs);
  foreach($campaignNIDs as $key => $value) {  
       $CampaignNID = $value;
       mymodule_collect_contact_actions($acc_id, $CampaignNID);
  }
}

And then I worked in the hook_cron

function mymodule_cron(){
  //Adding drupal_queue into the cron
  $items = mymodule_get_all_accounts();
  //This is the list of items that we need to itterate through
  //This will be the different ESP accounts
  $queue = drupal_queue_get('mymodule_queue'); //grab the queue
  $queue->createQueue(); //initiate the queue
  foreach ($items as $item) {
    $queue->createItem($item); //each item passed as param to worker
  }

  drupal_queue_cron_run();

So far this works and allows me to call each account separately in the queue. but now I have processes(functions) that need to be run per account. Ho would I add these processes as a "Sub-queue" to the queue that is currently being processed.

Do I need to do this or is what I have so far satisfactory?

Any light on this subject would be really appreciated as the documentation on this subject is somewhat lacking

1

There's no concept of a "sub-queue", it's just queues, items in the queue, and workers of a queue (on items). Without knowing more about your use case I'd say you should may want to have a queue per account. Or create a queue item containing the account its for and working that way. So, you can either have many queues with some items in each or one queue with a whole bunch of items.

1
  • I have spent some time now on understanding how the queue system works and how I can use it in conjunction with batches. Queues is a very useful tool when used with batches. Thank you for your explanation :) – Beyerz Sep 1 '12 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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