Browse Source

Added drush integration to check bulk loader running jobs status

Lacey Sanderson 12 years ago
parent
commit
125bd0dbfb

+ 47 - 0
tripal_bulk_loader/tripal_bulk_loader.drush.inc

@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * Implements drush integration for this module
+ */
+
+/**
+ * Implements hook_drush_command().
+ */
+function tripal_bulk_loader_drush_command() {
+  $items = array();
+  $items['tripal-loader-progress'] = array(
+    'description' => dt('Display the progress of any running tripal bulk loading job.'),
+    'aliases' => array('trpload-%'),
+  );
+  return $items;
+}
+
+/**
+ * Code ran for the tripal-loader-progress drush command
+ * Display the progress of any running tripal bulk loading job.
+ */
+function drush_tripal_bulk_loader_tripal_loader_progress () {
+
+  // determine the progress of any loading jobs
+  $sql = "SELECT t.loader_name, t.file, t.job_id FROM tripal_bulk_loader t WHERE job_status='Loading...'";
+  $resource = db_query($sql);
+
+  while ($r = db_fetch_object($resource)) {
+    if ($r->job_id) {
+      $progress = tripal_bulk_loader_progess_file_get_progress($r->job_id);
+      if ($progress->num_records > 0 AND $progress->total_percent < 100) {
+        drush_print(
+          $r->loader_name . "\n"
+          . str_repeat("-", 40) . "\n"
+          . "File:" . $r->file . "\n"
+          . "Current Constant Set:\n"
+          . "\tLines processed: " . $progress->num_lines . "\n"
+          . "\tRecord Inserted: " .$progress->num_records . "\n"
+          . "\tPercent Complete: " . $progress->percent_file . "\n"
+          . "Number of Constant Sets fully loaded: " . $progress->num_constant_sets_loaded . "\n"
+          . "Job Percent Complete: " . $progress->total_percent . "\n"
+        );
+      }
+    }
+  }
+}

+ 4 - 0
tripal_bulk_loader/tripal_bulk_loader.module

@@ -490,6 +490,10 @@ function tripal_bulk_loader_preprocess_tripal_bulk_loader_template(&$variables)
  */
 function tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress = TRUE) {
   $filename = '/tmp/tripal_bulk_loader_progress-'.$job_id.'.out';
+  if (!file_exists($filename)) {
+    return (object) array();
+  }
+
   $num_lines = trim(`wc --lines < $filename`);
   $num_records = trim(`grep -c "." $filename`);