We bulk upload nodes on our Drupal site. Those nodes need to be Solr indexed all at once, without having to wait for cron to index them. The cron job indexes apachesolr_cron_limit nodes per run. As a result, if I have 40.000 records, I have to wait too long.
A solution I implemented is, creating a button which indexes all remaining. The button runs the code below.
function mymodule_index_all_remaining() {
variable_set('cron_safe_threshold', 0); // Doen not work.
module_load_include('inc', 'apachesolr', 'apachesolr.admin');
$env_id = apachesolr_default_environment();
apachesolr_index_batch_index_remaining($env_id);
variable_set('cron_safe_threshold', 10800); // Does not work.
}
My problem is that we have cron running every 3 hours and when the cron begins (while the mymodule_index_all_remaining is still running), I get HTTP 502 error. The same error occurs if I try to index the remaining from admin/config/search/apachesolr Index all queued content.
So I need to alter the cron interval, which can been seen under admin/config/system/cron, "Run cron every". This interval is stored in a static variable cron_safe_threshold. I tried to set it to 0, but it doesn't work. I cannot change settings.php as I really want cron to run evey 3 hours when the indexing does not run. Is there another way to pause cron jobs from running while another process takes place?
Do you recomment another way to index remaining without having the 502 error?