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