Browse Source

Updated drush function so that it runs the tripal daemon :)

Lacey Sanderson 10 years ago
parent
commit
ecdfa2c99e

+ 6 - 6
tripal_daemon/classes/TripalJobDaemon.inc

@@ -5,7 +5,7 @@
  */
 class TripalJobDaemon {
 
-  // Maximum Memory Threshold
+  // Maximum Memory Usage Allowed
   // During Health checks, if the memory usage is over this % usage for the system
   // then the child process will kill re-fork and kill itself
   protected $memory_threshold = 0.85;
@@ -26,10 +26,10 @@ class TripalJobDaemon {
   protected $file_path;
 
   // The filename & path of the log file
-  protected $log_filename;
+  public $log_filename;
 
   // The filename & path of the status file
-  protected $status_filename;
+  public $status_filename;
 
   /**
    * Creates a new TripalDaemon object
@@ -39,11 +39,11 @@ class TripalJobDaemon {
     // Set the log/status files
     $this->file_path = (isset($args['file_path'])) ? $args['file_path'] : '/tmp';
 
-    $this->log_filename = (isset($args['logfile'])) ? $args['logfile'] : 'tripaljobs_daemon.log';
-    $this->log_filename = $this->file_path . $this->log_filename;
+    $this->log_filename = (isset($args['log_filename'])) ? $args['log_filename'] : 'tripaljobs_daemon.log';
+    $this->log_filename = $this->file_path . '/' . $this->log_filename;
 
     $this->status_filename = (isset($args['status_filename'])) ? $args['status_filename'] : 'tripaljobs_daemon.status.json';
-    $this->status_filename = $this->file_path . $this->status_filename;
+    $this->status_filename = $this->file_path . '/' . $this->status_filename;
 
     // If the wait time is provided then set it to the provided value
     if (isset($args['wait_time'])) {

+ 37 - 5
tripal_daemon/tripal_daemon.drush.inc

@@ -30,7 +30,15 @@ function tripal_daemon_drush_command() {
       'show-log' => 'Show the log file.',
     ),
     'options' => array(
-      //'--feedback' => 'Frequency of progress messages, in seconds or items processed.',
+      'memory_threshold' => 'The maximum memory usage allowed before the daemon should kill itself. Default: 0.85',
+      'wait_time' => 'The amount of seconds to wait before checking whether a Tripal Job has been submitted. Default: 60.',
+      'file_path' => 'The filepath to store the log and status files to. This should be
+        either the sites/default/files directory for your Drupal site or the /tmp directory. Default: /tmp.',
+      'log_filename' => 'The name of the logfile. Default: tripaljobs_daemon.log',
+      'status_filename' => array(
+        'description' => 'The name of the file containing a JSON array describing the status of the Daemon. Default: tripaljobs_daemon.status.json',
+        'hidden' => TRUE
+      )
     ),
     'examples' => array(
       'drush trpjob-daemon start'                            => 'Start the daemon.',
@@ -40,11 +48,11 @@ function tripal_daemon_drush_command() {
       ' '   => '',
       'drush trpjob-daemon status' => 'Show the current status of the daemon.',
       '  '  => '',
-      'drush trpjob-daemon stop'              => 'Stop the daemon, allowing 45 seconds for processing.',
+      'drush trpjob-daemon stop'              => 'Stop the daemon.',
       //'drush trpjob-daemon stop --timeout=10' => 'Allow 10 seconds for processing.',
       //'drush trpjob-daemon stop --queue'      => 'Queue the node access rebuild daemon to stop.',
       '   ' => '',
-      'drush trpjob-daemon restart'              => 'Restart the daemon, allowing 45 seconds for processing.',
+      'drush trpjob-daemon restart'              => 'Restart the daemon.',
       //'drush trpjob-daemon restart --timeout=10' => 'Allow 10 seconds for processing.',
       //'drush trpjob-daemon restart --queue'      => 'Queue the node access rebuild daemon to restart.',
       '    ' => '',
@@ -67,7 +75,31 @@ function tripal_daemon_drush_command() {
  */
 function drush_tripal_daemon_tripal_jobs_daemon($action) {
 
-  drush_print("\nTripal Jobs Daemon\n".str_repeat("=",60)."\n");
-  drush_print(" You have choosen to $action the daemon.\n");
+  $details = tripal_daemon_drush_command();
+  $supported_options = array_keys($details['tripal-jobs-daemon']['options']);
 
+  $script_path = drupal_get_path('module','tripal_daemon');
+  $module_path = DRUPAL_ROOT . '/' . drupal_get_path('module','tripal_daemon');
+
+  $output = NULL;
+  $return_value = NULL;
+  $options = array();
+  foreach ($supported_options as $opt) {
+    $val = drush_get_option($opt);
+    if ($val) {
+      $options[] = $opt . '=' . $val;
+    }
+  }
+  $command = "php $script_path/tripal_daemon_script.php $action module_path=$module_path " . implode(" ",$options);
+  exec($command, $output, $return_value);
+  drush_print(implode("\n",$output));
+
+  switch($return_value) {
+    case 0:
+      drush_log("Daemon started successfully.",'ok');
+      break;
+    default:
+      drush_log("Unable to $action the Daemon.",'error');
+      break;
+  }
 }

+ 3 - 8
tripal_daemon/tripal_daemon_script.php

@@ -1,15 +1,8 @@
 <?php
 
-require_once 'classes/TripalDaemon.inc';
-
 /**
  * This is the script that is actually Daemonized.
- *
- * Arguments expected to be passed to this script:
- *  - action: One of 'start','stop','restart',status','show-log'. Meant to indicate what
- *       you want the daemon to do.
- *  - log_file: the full path & filename of the log file. If it doesn't exist this script will
- *       create it.
+ * Expected to be run via Drush tripal-jobs-daemon
  */
 
 // Get Command-line Variables
@@ -19,11 +12,13 @@ if (!$action) {
   die('You need to specify what you want the Daemon to do. This should be one of: start, stop, restart, status, show-log');
 }
 
+require_once $args['module_path'] . '/classes/TripalJobDaemon.inc';
 $Daemon = new TripalJobDaemon($args);
 
 print "\nTripal Jobs Daemon\n".str_repeat("=",60)."\n";
 print "Memory Threshold: " . ($Daemon->get_memory_threshold() * 100) . "%\n";
 print "Wait Time: ". $Daemon->get_wait_time() . " seconds\n";
+print "Log File: " . $Daemon->log_filename . "\n";
 print "\n";
 
 // Check that the action is valid and then execute it