/**
  * 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();
     }
 }
 /**
  * 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();
 }
 /**
  * Create the filter/sort form at the top of a list of exports.
  *
  * This handles the very default conditions, and most lists are expected
  * to override this and call through to parent::list_form() in order to
  * get the base form and then modify it as necessary to add search
  * gadgets for custom fields.
  */
 public function list_form(&$form, &$form_state)
 {
     parent::list_form($form, $form_state);
     $class = _ultimate_cron_get_class('job');
     $lock_ids = $class::isLockedMultiple($this->items);
     $log_entries = $class::loadLatestLogEntries($this->items);
     $progresses = $class::getProgressMultiple($this->items);
     foreach ($this->items as $name => $item) {
         $item->log_entry = isset($item->log_entry) ? $item->log_entry : $log_entries[$name];
         $item->progress = isset($item->progress) ? $item->progress : $progresses[$name];
         $item->lock_id = isset($item->lock_id) ? $item->lock_id : $lock_ids[$name];
     }
     $form['#attached']['js'][] = drupal_get_path('module', 'ultimate_cron') . '/js/ultimate_cron.js';
     if (module_exists('nodejs')) {
         $settings = _ultimate_cron_plugin_load('settings', 'general')->getDefaultSettings();
         if (!empty($settings['nodejs'])) {
             nodejs_send_content_channel_token('ultimate_cron');
             $form['#attached']['js'][] = drupal_get_path('module', 'ultimate_cron') . '/js/ultimate_cron.nodejs.js';
         }
     }
     // There's no normal for Ultimate Cron!
     unset($form['top row']['storage']['#options'][t('Normal')]);
     $all = array('all' => t('- All -'));
     $options = $all + array('running' => 'running', -1 => 'no info') + watchdog_severity_levels();
     $form['top row']['status'] = array('#type' => 'select', '#title' => t('Status'), '#options' => $options, '#default_value' => 'all', '#weight' => -2);
     $jobs = ultimate_cron_get_hooks();
     $modules = array();
     foreach ($jobs as $job) {
         $info = system_get_info('module', $job['module']);
         $modules[$job['module']] = $info && !empty($info['name']) ? $info['name'] : $job['module'];
     }
     $form['top row']['module'] = array('#type' => 'select', '#title' => t('Module'), '#options' => $all + $modules, '#default_value' => 'all', '#weight' => -1);
     $form['bottom row']['reload'] = array('#type' => 'submit', '#id' => 'ctools-export-ui-list-items-reload', '#value' => t('Reload'), '#attributes' => array('class' => array('use-ajax-submit')));
 }