log("Jobs are still running. Use the --parallel=1 option with the Drush command to run jobs in parallel.\n"); } elseif ($do_parallel && tripal_max_jobs_exceeded($max_jobs)) { $this->log("At least $max_jobs jobs are still running. At least one of these jobs much complete before a new job can start.\n"); } else { // First check to see if there are any tripal jobs to be run. $sql = " SELECT TJ.job_id FROM {tripal_jobs} TJ WHERE TJ.start_time IS NULL AND TJ.end_time IS NULL AND NOT TJ.status = 'Cancelled' ORDER BY priority ASC,job_id ASC"; $job_ids = db_query($sql)->fetchCol(); $num_waiting_jobs = sizeof($job_ids); // If there are then run them and log the output. if ($num_waiting_jobs > 0) { $this->log($num_waiting_jobs . ' Waiting Tripal Jobs... ' . 'Running waiting job(s) now.'); // Launch all tripal jobs :) Yay for bootstrapping!! foreach ($job_ids as $id) { $this->log('Starting Job (ID=' . $id . ')', '', 1); // Tell admins we are running a job. $this->tripal_jobs[$id] = $id; $this->setStatus(); // Launch Tripal Job. $job = new TripalJob(); $job->load($id); try { $job->run(); } catch (Exception $e) { $job->logMessage($e->getMessage(), array(), TRIPAL_ERROR); } // Tell admins that we're done :-). unset($this->tripal_jobs[$id]); $this->setStatus(); // Report job details. $job = db_query( "SELECT j.* FROM {tripal_jobs} j WHERE j.job_id = :jid", array(':jid' => $id) )->fetchObject(); $this->log("Job (ID=" . $id . ") completed at " . date('d M Y H:i:s', $job->end_time) . " with a status of '" . $job->status . "'", "", 1); } } } } /** * Override to include additional daemon-specific settings for use in reports. * * @return array * An array of status details where the key should be a human-readable * name for your detail and the value should be the current state. */ protected function getStatusDetails() { $status_details = parent::getStatusDetails(); $status_details['Running Job'] = (empty($this->tripal_jobs)) ? FALSE : TRUE; $status_details['Current Jobs'] = $this->tripal_jobs; return $status_details; } }