소스 검색

Fixed bug in gff loader, and added 'cancel' and 're-run' actions to the jobs page

spficklin 14 년 전
부모
커밋
b172b7459a
4개의 변경된 파일98개의 추가작업 그리고 50개의 파일을 삭제
  1. 67 9
      tripal_core/jobs.php
  2. 1 1
      tripal_core/tripal_core.api.inc
  3. 16 0
      tripal_core/tripal_core.module
  4. 14 40
      tripal_feature/gff_loader.php

+ 67 - 9
tripal_core/jobs.php

@@ -66,15 +66,20 @@ function tripal_get_module_active_jobs ($modulename){
 */
 function tripal_jobs_report () {
    //$jobs = db_query("SELECT * FROM {tripal_jobs} ORDER BY job_id DESC");
-   $jobs = pager_query("SELECT * FROM {tripal_jobs} TJ INNER JOIN users U on TJ.uid = U.uid ORDER BY job_id DESC",
-      10,0,"SELECT count(*) FROM {tripal_jobs}");
+   $jobs = pager_query(
+      "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
+              TJ.status as job_status, TJ,submit_date,TJ.start_time,
+              TJ.end_time,TJ.priority
+       FROM {tripal_jobs} TJ 
+         INNER JOIN users U on TJ.uid = U.uid 
+       ORDER BY job_id DESC", 10,0,"SELECT count(*) FROM {tripal_jobs}");
 	
    // create a table with each row containig stats for 
    // an individual job in the results set.
    $output .= "Waiting jobs are executed first by priority level (the lower the ".
               "number the higher the priority) and second by the order they ".
               "were entered";
-   $output .= "<table class=\"border-table\">". 
+   $output .= "<table class=\"tripal-table tripal-table-horz\">". 
               "  <tr>".
               "    <th>Job ID</th>".
               "    <th>User</th>".
@@ -83,21 +88,35 @@ function tripal_jobs_report () {
 			     "    <th>Priority</th>".
 			     "    <th>Progress</th>".
               "    <th>Status</th>".
+              "    <th>Actions</th>".
               "  </tr>";
-   
+   $i = 0;
    while($job = db_fetch_object($jobs)){
+      $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
+      if($i % 2 == 0 ){
+         $class = 'tripal_feature-table-odd-row tripal-table-even-row';
+      }
       $submit = format_date($job->submit_date);
       if($job->start_time > 0){
          $start = format_date($job->start_time);
       } else {
-         $start = 'Not Yet Started';
+         if(strcmp($job->job_status,'Cancelled')==0){
+            $start = 'Cancelled';
+         } else {
+            $start = 'Not Yet Started';
+         }
       }
       if($job->end_time > 0){
          $end = format_date($job->end_time);
       } else {
          $end = '';
       }
-      $output .= "  <tr>";
+      $cancel_link = '';
+      if($job->start_time == 0 and $job->end_time == 0){
+         $cancel_link = "<a href=\"".url("admin/tripal/tripal_jobs/cancel/".$job->job_id)."\">Cancel</a>";
+      }
+      $rerun_link = "<a href=\"".url("admin/tripal/tripal_jobs/rerun/".$job->job_id)."\">Re-run</a>";
+      $output .= "  <tr $class>";
       $output .= "    <td>$job->job_id</td>".
                  "    <td>$job->name</td>".
                  "    <td>$job->job_name</td>".
@@ -106,8 +125,10 @@ function tripal_jobs_report () {
                  "    <br>End Time: $end</td>".
                  "    <td>$job->priority</td>".
 				     "    <td>$job->progress%</td>".
-                 "    <td>$job->status</td>".
+                 "    <td>$job->job_status</td>".
+                 "    <td>$cancel_link $rerun_link</td>".
                  "  </tr>";
+      $i++;
    }
    $output .= "</table>";
 	$output .= theme_pager();
@@ -130,7 +151,7 @@ function tripal_jobs_launch (){
    // get all jobs that have not started and order them such that
    // they are processed in a FIFO manner. 
    $sql =  "SELECT * FROM {tripal_jobs} TJ ".
-           "WHERE TJ.start_time IS NULL ".
+           "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL ".
            "ORDER BY priority ASC,job_id ASC";
    $job_res = db_query($sql);
    while($job = db_fetch_object($job_res)){
@@ -193,4 +214,41 @@ function tripal_jobs_check_running () {
    // return 1 to indicate that no jobs are currently running.
    return 0;
 }
-?>
+
+/**
+*
+*/
+function tripal_jobs_rerun ($job_id){
+   global $user;
+
+   $sql = "select * from {tripal_jobs} where job_id = %d";
+   $job = db_fetch_object(db_query($sql,$job_id));
+
+   $args = explode("::",$job->arguments);
+   tripal_add_job ($job->job_name,$job->modulename,$job->callback,$args,$user->uid,
+      $job->priority);
+
+   drupal_goto("admin/tripal/tripal_jobs");
+}
+
+/**
+*
+*/
+function tripal_jobs_cancel ($job_id){
+   $sql = "select * from {tripal_jobs} where job_id = %d";
+   $job = db_fetch_object(db_query($sql,$job_id));
+
+   // set the end time for this job
+   if($job->start_time == 0){
+      $record = new stdClass();
+      $record->job_id = $job->job_id;
+	   $record->end_time = time();
+	   $record->status = 'Cancelled';
+	   $record->progress = '0';
+	   drupal_write_record('tripal_jobs',$record,'job_id');
+      drupal_set_message("Job #$job_id cancelled");
+   } else {
+      drupal_set_message("Job #$job_id cannot be cancelled. It is in progress or has finished.");
+   }
+   drupal_goto("admin/tripal/tripal_jobs");
+}

+ 1 - 1
tripal_core/tripal_core.api.inc

@@ -457,7 +457,7 @@ function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
    if(!$has_record){
       return $results;
    } else{
-      return scalar($results);
+      return count($results);
    }
 }
 /**

+ 16 - 0
tripal_core/tripal_core.module

@@ -110,6 +110,22 @@ function tripal_core_menu() {
      'access arguments' => array('access administration pages'),
      'type' => MENU_NORMAL_ITEM,
    );
+   $items['admin/tripal/tripal_jobs/cancel/%'] = array(
+     'title' => 'Jobs',
+     'description' => 'Cancel a pending job',
+     'page callback' => 'tripal_jobs_cancel',
+     'page arguments' => array(4),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_CALLBACK,
+   );
+   $items['admin/tripal/tripal_jobs/rerun/%'] = array(
+     'title' => 'Jobs',
+     'description' => 'Re-run an existing job.',
+     'page callback' => 'tripal_jobs_rerun',
+     'page arguments' => array(4),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_CALLBACK,
+   );
    $items['admin/tripal/tripal_mview/%'] = array(
      'title' => 'Materialized View',
      'description' => 'Materialized views are used to improve speed of large or complex queries.',

+ 14 - 40
tripal_feature/gff_loader.php

@@ -332,7 +332,6 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
       $attr_is_analysis = 'f';
       $attr_others = '';
       $residues = '';
-      $generate_name = 0;
       foreach($attrs as $attr){
          $attr = rtrim($attr);
          $attr = ltrim($attr);
@@ -366,7 +365,13 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
 
       // if neither name nor uniquename are provided then generate one
       if(!$attr_uniquename and !$attr_name){
-         $generate_name = 1;
+         if(array_key_exists('Parent',$tags)){
+            $attr_uniquename = $tags['Parent'][0]."-$type-$landmark:$fmin..$max";
+         } else { 
+           print "ERROR: cannot generate a uniquename for feature on line $i\n";
+           exit;
+         }
+         $attr_name = $attr_uniquename;
       }
 
       // if a name is not specified then use the unique name
@@ -407,7 +412,7 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
       
       // if the option is to remove or refresh then we want to remove
       // the feature from the database.
-      if(!$generate_name and ($remove or $refresh)){
+      if($remove or $refresh){
          print "Removing feature '$attr_uniquename'\n";
          $sql = "DELETE FROM {feature}
                  WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
@@ -425,17 +430,14 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
          // add/update the feature
          $feature = tripal_core_load_gff3_feature($organism,$analysis_id,$cvterm,
             $attr_uniquename,$attr_name,$residues,$attr_is_analysis,
-            $attr_is_obsolete, $add_only,$generate_name);
+            $attr_is_obsolete, $add_only);
 
          // store all of the features so far use later by parent and target
          // relationships
          $gff_features[$feature->uniquename]['type'] = $type;
 
          if($feature){
-            if($generate_name){
-               $attr_uniquename = $feature->uniquename;
-            }
- 
+
             // add/update the featureloc if the landmark and the ID are not the same
             // if they are the same then this entry in the GFF is probably a landmark identifier
             if(strcmp($landmark,$attr_uniquename)!=0){
@@ -698,11 +700,7 @@ function tripal_core_load_gff3_alias($feature,$aliases){
  * @ingroup gff3_loader
  */
 function tripal_core_load_gff3_feature($organism,$analysis_id,$cvterm,$uniquename,$name,
-   $residues,$is_analysis='f',$is_obsolete='f',$add_only,$generate_name)  {
-
-   if($generate_name){
-      $uniquename = 'tripal_temp_loading_name' . rand(1,99999999);
-   }
+   $residues,$is_analysis='f',$is_obsolete='f',$add_only)  {
 
    // check to see if the feature already exists
    $feature_sql = "SELECT * FROM {feature} 
@@ -761,24 +759,6 @@ function tripal_core_load_gff3_feature($organism,$analysis_id,$cvterm,$uniquenam
       }
    }
 
-   // now that we've added the feature let's reset it's uniquename to be
-   // the feature id
-   if($generate_name){
-      $usql = "UPDATE {feature} 
-               SET name = '%s', uniquename = '%s'
-               WHERE feature_id = %d";
-      print "   Renaming feature '$uniquename' => ";
-      $uniquename = "$feature->feature_id";
-      print "$uniquename\n";
-      $result = db_query($usql,$uniquename,$uniquename,$feature_id);
-      if(!$result){
-         print "ERROR: failed to update unnamed feature '$uniquename' with generic name\n";
-         return 0;
-      }
-      $feature->name = $uniquename;
-      $feature->uniquename = $uniquename;
-   }
-
    return $feature;
 }
 
@@ -810,9 +790,7 @@ function tripal_core_load_gff3_featureloc($feature,$organism,$landmark,$fmin,
    // last rank value
    $rank = -1;  
    $exists = 0;  
-   $featureloc_sql = "SELECT FL.featureloc_id,FL.fmin,FL.fmax, FL.is_fmin_partial,
-                         FL.is_fmax_partial, FL.strand, FL.phase, FL.residue_info,
-                         FL.locgroup, F.uniquename as srcname
+   $featureloc_sql = "SELECT FL.featureloc_id,FL.fmin,FL.fmax,F.uniquename as srcname
                       FROM {featureloc} FL
                         INNER JOIN {feature} F on F.feature_id = FL.srcfeature_id
                       WHERE FL.feature_id = %d
@@ -820,11 +798,7 @@ function tripal_core_load_gff3_featureloc($feature,$organism,$landmark,$fmin,
    $recs = db_query($featureloc_sql,$feature->feature_id);
    while ($featureloc = db_fetch_object($recs)){
       if(strcmp($featureloc->srcname,$landmark)==0 and
-         $featureloc->fmin == $fmin and strcmp($featureloc->is_fmin_partial,$is_fmin_partial)==0 and
-         $featureloc->fmax == $fmax and strcmp($featureloc->is_fmax_partial,$is_fmax_partial)==0 and
-         $featureloc->phase == $phase and $featureloc->strand == $strand and
-         strcmp($featureloc->residue_info,$residue_info)==0 and 
-         $featureloc->locgroup == $locgroup){
+         $featureloc->fmin == $fmin and $featureloc->fmax == $fmax){
          // this is the same featureloc, so do nothing... no need to update
          //TODO: need more checks here
          print "   No change to featureloc\n";
@@ -859,7 +833,7 @@ function tripal_core_load_gff3_featureloc($feature,$organism,$landmark,$fmin,
                $strand,$phase,$residue_info,$locgroup,$rank);
       if(!$result){
          print "ERROR: failed to insert featureloc\n";
-exit;
+         exit;
          return 0;
       }
    }