/** * Background Process launch. */ public function launch($job) { $lock_id = $job->lock(); if (!$lock_id) { return FALSE; } $settings = $job->getSettings($this->type); $handle = 'uc-' . $job->name; $process = new BackgroundProcess($handle); $this->exec_status = $this->status = BACKGROUND_PROCESS_STATUS_LOCKED; // Always run cron job as anonymous user. $process->uid = 0; $process->service_group = $settings['service_group']; $service_host = $process->determineServiceHost(); if ($this->scheduledLaunch) { $init_message = t('Launched at service host @name', array('@name' => $service_host)); } else { $init_message = t('Launched manually at service host @name', array('@name' => $service_host)); } // We know that the latest log entry has been used for determining the // schedule. Load the latest log entry and store the timestamp of it for // later use. if (!empty($job->recheck)) { $log_entry = isset($job->log_entry) ? $job->log_entry : $job->loadLatestLogEntry(); $recheck = $log_entry->start_time; } else { $recheck = FALSE; } $log_entry = $job->startLog($lock_id, $init_message); if (!$process->execute(array(get_class($this), 'job_callback'), array($job->name, $lock_id, $recheck))) { watchdog('bgpl_launcher', 'Could not execute background process dispatch for handle @handle', array('@handle' => $handle), WATCHDOG_ERROR); $log_entry->finish(); $this->unlock($lock_id); return FALSE; } // We want to finish the log in the sub-request. $log_entry->unCatchMessages(); drupal_set_message(t('@name: @init_message', array('@name' => $job->name, '@init_message' => $init_message))); return TRUE; }