If you have Ultimate Cron as one of a large enough number of modules (say > 100) in an install profile, having hook_init triggering during the batch task of module enabling will cause all sorts of intermittent and highly variable issues and crashes and timeouts. Once a background task and poormans cron is going against a foreground of ajax calls and serial module installation, who knows what's possible.

A smaller set of modules culled from the same general project here (~50 modules) generally installs ok as an installation profile, even though it's including Ultimate Cron, and the background process for poorman's cron is running. So most people probably won't see this happen.

If you look at what background_process is doing in background_process_init(), something very similar should be in ultimate_cron_init():

  // Only determine when installation of site is finished
  if (!variable_get('install_profile', FALSE)) {
    return;
  }

The workaround we use for now is to add a step into the install profile (/profiles/myprofile/myprofile.profile) in which we disable that poorman's cron launch.

/**
 * Implements hook_install_tasks_alter().
 */
function myprofile_install_tasks_alter(&$tasks, $install_state) {
  $new_tasks = array();
  foreach ($tasks as $name => $task) {
    $new_tasks[$name] = $task;
    if ($name == 'install_bootstrap_full') {
      // we must insert after install_bootstrap_full if we want variable_get/set to work

      // add an invisible task to prepare for module installation
      $new_tasks['install_prepare_for_install_profile_modules'] = array(
        'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
        'function' => 'myprofile_install_prepare_for_install_profile_modules',
      );
    }
  }
  $tasks = $new_tasks;
}

/**
 * Callback for the myprofile_install_prepare_for_install_profile_modules step.
 */
function myprofile_install_prepare_for_install_profile_modules(&$install_state) {
  // this will stop Ultimate Cron from launching a background process following install.
  variable_set('ultimate_cron_poorman', FALSE);
}
CommentFileSizeAuthor
#3 install-profile-friendly.patch591 bytesgielfeldt

Comments

gielfeldt’s picture

Hi

Thanks for this. I can also see now, that it may cause problems on systems requiring the default service host determination, as the poorman cron is launched before this happens.

It seems checking on 'install_profile' might be too soon, as background_process is using 'install_task' as an indicator.

I could check against 'install_task' in Ultimate Cron, but it has 2 drawbacks:

1.) If the Ultimate Cron module were to get a lower weight than Background Process, it would (attempt to) launch the poormans cron before Background Process is done initializing.
2.) The Drupal installation finish process runs regular cron. This means that the cronrun timestamp is updated, and there UC's poormans cron will not be launched until a request is made to the website at least one minute after installation is done.

Do you think the above would be acceptable?

Problem 2 could be solved in various ways. Problem 1 I'm not so sure about how to do without too tight a coupling from Background Process to Ulitmate Cron.

Perhaps I'll implement it just to begin with, as it at least seems more robust than the current implementation.

Thoughts?

exratione’s picture

install_task is set to 'done' and install_profile is set to the profile name at about the same time. I agree that install_task is probably better / more 'official'.

Re: #1) I think that telling people not to set the weight of a module lower than that of another module it depends on is very reasonable.

Re: #2) That isn't an issue for my use-case, but it seems not too terrible for anyone else either.

gielfeldt’s picture

Status: Active » Needs review
StatusFileSize
new591 bytes

Wanna test it?

exratione’s picture

Patch in #3 works for me.

gielfeldt’s picture

Committed to 6.x-1.x and 7.x-1.x.

gielfeldt’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

slip