Browse Source

Added better reporting to the daemon so admin know if a job is being run and if so, which job.

Lacey Sanderson 7 years ago
parent
commit
9093949973

+ 29 - 0
tripal_daemon/TripalDaemon.inc

@@ -23,6 +23,11 @@ class TripalDaemon extends DrushDaemon {
   // inherits from a library class.
   protected $loop_interval = 20;
 
+  // Keep track of whether we are running a Tripal job or not
+  // and if so, which Tripal jobs are we running.
+  // If this array is empty then we are waiting for jobs ;-).
+  protected $tripal_jobs = array();
+
   /**
    * Implements DaemonAPIDaemon::executeTask() function.
    *
@@ -87,9 +92,17 @@ class TripalDaemon extends DrushDaemon {
         // Start Buffering.
         ob_start();
 
+        // Tell admins we are running a job.
+        $this->tripal_jobs[$id] = $id;
+        $this->setStatus();
+
         // Launch Tripal Job.
         tripal_launch_job(FALSE, $id);
 
+        // Tell admins that we're done :-).
+        unset($this->tripal_jobs[$id]);
+        $this->setStatus();
+
         // Save the buffer to the log and stop buffering.
         $this->log(str_repeat('=', 80));
         $this->log(ob_get_clean());
@@ -112,4 +125,20 @@ class TripalDaemon extends DrushDaemon {
     }
 
   }
+
+  /**
+   * 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;
+  }
 }

+ 37 - 3
tripal_daemon/includes/tripal_daemon.blocks.inc

@@ -56,27 +56,41 @@ function theme_tripal_daemon_status_block_content($show_all = FALSE) {
   $is_running = drushd_is_daemon_running('tripal_daemon');
   $status_file = drushd_get_daemon_status_file('tripal_daemon');
   $status = unserialize(file_get_contents($status_file));
+  $PID = $status['PID'];
+  $is_alive = `ps h --pid $PID | wc -l`;
+  $is_alive = trim($is_alive);
 
   $status_class = ($is_running) ? 'active' : 'inactive';
+  $status_class = ($is_running AND !$is_alive) ? 'dead' : $status_class;
 
   // Theme content.
   drupal_add_css(drupal_get_path('module','tripal_daemon') . '/theme/status_block.css');
 
   // Display the status.
   $output .= '<div class="daemon-status">';
-  if ($is_running) {
+  if ($is_running and $is_alive) {
     $output .= theme_image(array(
       'path' => 'misc/message-24-ok.png',
       'alt' => 'status-ok',
     ));
-    $output .= 'Running';
+    if ($status['Running Job']) {
+      $output .= 'Running Job(s)';
+    }
+    else {
+      $output .= 'Waiting for Job';
+    }
   }
   else {
     $output .= theme_image(array(
       'path' => 'misc/message-24-error.png',
       'alt' => 'status-error',
     ));
-    $output .= 'Stopped';
+    if ($is_running AND !$is_alive) {
+      $output .= 'Dead';
+    }
+    else {
+      $output .= 'Stopped';
+    }
   }
   $output .= '</div>';
 
@@ -84,10 +98,30 @@ function theme_tripal_daemon_status_block_content($show_all = FALSE) {
   if ($show_all) {
     $output .= '<ul>';
     foreach ($status as $k => $v) {
+
+      // If it's a boolean, then make it readable.
       if (is_bool($v)) {
         $v = ($v) ? 'True' : 'False';
       }
 
+      // If these are current jobs then we want to link to details.
+      if ($k == 'Current Jobs' AND !empty($v)) {
+        foreach ($v as $job_id) {
+          $url = 'admin/tripal/tripal_jobs/view/' . $job_id;
+          $v[$job_id] = l($job_id, $url);
+        }
+      }
+
+      // If it's an array then make it a list.
+      if (is_array($v)) {
+        if (empty($v)) {
+          $v = 'None';
+        }
+        else {
+          $v = implode(', ', $v);
+        }
+      }
+
       $output .= '<li><strong>' . $k . '</strong>: ' . $v . '</li>';
     }
     $output .= '</ul>';

+ 5 - 1
tripal_daemon/theme/status_block.css

@@ -13,10 +13,14 @@ div.block-tripal-daemon .active {
   background-color: #f8fff0; 
   color: #234600;
 }
-div.block-tripal-daemon .inactive {
+div.block-tripal-daemon .dead {
   background-color: #fef5f1;
   color: #8c2e0b;
 }
+div.block-tripal-daemon .inactive {
+  background-color: #fef5f1;
+  color: #b3b3b3;
+}
 
 div.block-tripal-daemon .daemon-status {
   font-weight: bolder;