/** * Poorman launcher background process callback. * * @param string $lock_id * The lock id used for this process. */ public static function poormanLauncher($lock_id) { $class = _ultimate_cron_get_class('lock'); // Bail out if someone stole our lock. if (!$class::reLock($lock_id, 60)) { return; } ultimate_cron_poorman_page_flush(); // Wait until it's our turn (0 seconds at next minute). $cron_last = variable_get('cron_last', 0); $cron_next = floor(($cron_last + 60) / 60) * 60; $time = time(); if ($time < $cron_next) { $sleep = $cron_next - $time; sleep($sleep); } // Get settings, so we can determine the poormans cron service group. $plugin = _ultimate_cron_plugin_load('launcher', 'background_process_legacy'); if (!$plugin) { $class::unlock($lock_id); throw new Exception(t('Failed to load launcher plugin?!?!?!?!')); } $settings = $plugin->getDefaultSettings(); // In case launchers fail, we don't want to relaunch this process // immediately. _ultimate_cron_variable_save('cron_last', time()); // It's our turn! $launchers = array(); foreach (_ultimate_cron_job_load_all() as $job) { $launcher = $job->getPlugin('launcher'); $launchers[$launcher->name] = $launcher->name; } foreach ($launchers as $name) { $process = new BackgroundProcess('_ultimate_cron_poorman_' . $name); $process->uid = 0; $process->service_group = $settings['poorman_service_group']; $process->start('ultimate_cron_run_launchers', array(array($name))); } // Bail out if someone stole our lock. if (!$class::reLock($lock_id, 60)) { return; } // Wait until it's our turn (0 seconds at next minute). $cron_last = _ultimate_cron_variable_load('cron_last', 0); $cron_next = floor(($cron_last + 60) / 60) * 60; $time = time(); if ($time < $cron_next) { $sleep = $cron_next - $time; sleep($sleep); } // Check poorman settings. If launcher has changed, we don't want // to keepalive. $poorman = _ultimate_cron_plugin_load('settings', 'poorman'); if (!$poorman) { return; } $settings = $poorman->getDefaultSettings(); if (!$settings['launcher'] || $settings['launcher'] !== 'background_process_legacy') { return; } background_process_keepalive(); }
/** * Poormans cron launcher. */ public function launchPoorman() { $class = _ultimate_cron_get_class('lock'); $settings = $this->getDefaultSettings(); // Is it time to run cron? $cron_last = variable_get('cron_last', 0); $cron_next = floor(($cron_last + 60) / 60) * 60; $time = time(); if ($time < $cron_next) { if ($settings['poorman_keepalive'] && ($lock_id = $class::lock('ultimate_cron_poorman_serial', 60))) { ultimate_cron_poorman_page_flush(); $sleep = $cron_next - $time; sleep($sleep); ultimate_cron_poorman_trigger(); $class::unLock($lock_id); } return; } unset($_GET['thread']); ultimate_cron_poorman_page_flush(); ultimate_cron_run_launchers(); // Check poorman settings. If launcher has changed, we don't want // to keepalive. $poorman = _ultimate_cron_plugin_load('settings', 'poorman'); if (!$poorman) { return; } $settings = $poorman->getDefaultSettings(); if (!$settings['launcher'] || $settings['launcher'] !== $this->name) { return; } $settings = $this->getDefaultSettings(); if ($settings['poorman_keepalive'] && ($lock_id = $class::lock('ultimate_cron_poorman_serial', 60))) { // Is it time to run cron? If not wait before re-launching. $cron_last = variable_get('cron_last', 0); $cron_next = floor(($cron_last + 60) / 60) * 60; $time = time(); if ($time < $cron_next) { $sleep = $cron_next - $time; sleep($sleep); } $class::unLock($lock_id); ultimate_cron_poorman_trigger(); } }