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();
  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?

1 Answer 1


You can use Elysia Cron. This module is a enhanced Cron that has, apart of many other improvements, a global disable option. As they say in a bug report this variable may help you:

It disables ALL cron tasks. (No cron will be executed).

Also Elysia Cron allows you to set complex schedules so you may fix your problem just with the right schedule.

  • Thanks for your response. Unfortunatelly I have to work with what I have, so I cannot install a new module. I need another workaround. What if I updated that variable using db_update? Is that possible and if yes is it risky?
    – Maggie
    Jun 12, 2014 at 9:05

Your Answer

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

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