Selaa lähdekoodia

Add job existance test

Abdullah Almsaeed 8 vuotta sitten
vanhempi
commit
15ad1ea90a
1 muutettua tiedostoa jossa 7 lisäystä ja 11 poistoa
  1. 7 11
      tripal_core/api/tripal_core.jobs.api.inc

+ 7 - 11
tripal_core/api/tripal_core.jobs.api.inc

@@ -287,28 +287,24 @@ function tripal_cancel_job($job_id, $redirect = TRUE) {
  *          Whether to redirect to the job page or not
  */
 function tripal_execute_job($job_id, $redirect = TRUE) {
-  global $user;
-
   $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = :job_id";
   $results = db_query($sql, array(':job_id' => $job_id));
   $job = $results->fetchObject();
 
+  // Check if the job exists
+  if($job->rowCount() <= 0) {
+    drupal_set_message(t("Job %job_id does not exist in our records.", array('%job_id' => $job_id)));
+    return;
+  }
+
   // set the end time for this job
   if ($job->end_time == 0) {
-    //$cmd = "drush trp-run-jobs --job_id=".escapeshellarg($job_id)." --username=".escapeshellarg($user->name)." --root=".DRUPAL_ROOT." 2>&1";
-    //$cmd = "echo \"Test\" > /tmp/drush-apache/cache/default/test.txt";
-    //exec($cmd, $output, $return_code);
-
     tripal_launch_job(1, $job_id);
-    //$response = 'Response <br>';
-    //foreach($output as $line) {
-      //$response .= $line." ";
-    //}
-    //drupal_set_message($cmd.'<br>'.$response."<br> exit code = $return_code", 'error');
   }
   else {
     drupal_set_message(t("Job %job_id cannot be executed. It has already finished.", array('%job_id' => $job_id)));
   }
+
   if ($redirect) {
     drupal_goto("admin/tripal/tripal_jobs/view/$job_id");
   }