Răsfoiți Sursa

Added new drush command to rerun job

spficklin 12 ani în urmă
părinte
comite
1987e29927
2 a modificat fișierele cu 40 adăugiri și 3 ștergeri
  1. 12 3
      tripal_core/includes/jobs.php
  2. 28 0
      tripal_core/tripal_core.drush.inc

+ 12 - 3
tripal_core/includes/jobs.php

@@ -443,15 +443,24 @@ function tripal_core_preprocess_tripal_core_job_view(&$variables) {
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_rerun($job_id) {
+function tripal_jobs_rerun($job_id, $goto_jobs_page = TRUE) {
   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_id = tripal_add_job(
+    $job->job_name, 
+    $job->modulename, 
+    $job->callback, 
+    $args, 
+    $user->uid,
     $job->priority);
-  drupal_goto("admin/tripal/tripal_jobs");
+    
+  if ($goto_jobs_page) {
+    drupal_goto("admin/tripal/tripal_jobs");
+  }
+  return $job_id;
 }
 
 /**

+ 28 - 0
tripal_core/tripal_core.drush.inc

@@ -72,6 +72,23 @@ function tripal_core_drush_command() {
     ),
     'aliases' => array('trpjob-run')
   );
+  $items['tripal-rerun-job'] = array(
+    // used by drush help
+    'description' => dt('Rerun any job in the queue.'),
+    'examples' => array(
+      'Normal Job' => 'drush tripal-rerun-job admin 2',
+      'Parallel Job' => 'drush tripal-rerun-job admin  2 --parallel=1'
+    ),
+    'arguments' => array(
+      'user' => dt('The Drupal username under which the job should be run.  The permissions for this user will be used.'),
+      'job_id' => dt('The job ID to run.'),    
+    ),
+    // supply options
+    'options' => array(
+      'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'),
+    ),
+    'aliases' => array('trpjob-rerun')
+  );
   return $items;
 }
 
@@ -107,6 +124,17 @@ function drush_tripal_core_tripal_launch_jobs($username) {
   }
 }
 
+/**
+ * Executes jobs in the Tripal Jobs Queue
+ *
+ * NOTE: The following code is executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called
+ */
+function drush_tripal_core_tripal_rerun_job($username, $job_id) {
+	
+  $new_job_id = tripal_jobs_rerun($job_id, FALSE);
+  drush_tripal_core_tripal_launch_jobs($username, $new_job_id);
+ 
+}
 /**
  * Prints details about the current running job
  *