tripal_daemon.drush.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * Implementation of the Tripal Daemon Drush commands
  5. */
  6. /**
  7. * Implements hook_drush_help().
  8. */
  9. function tripal_daemon_drush_help($command) {
  10. switch ($command) {
  11. case 'drush:tripal-jobs-daemon':
  12. return dt('Use Tripal Jobs Deamon to manage Tripal Job execution.');
  13. }
  14. }
  15. /**
  16. * Implements hook_drush_command().
  17. */
  18. function tripal_daemon_drush_command() {
  19. $items = array();
  20. $items['tripal-jobs-daemon'] = array(
  21. 'description' => dt('Use Tripal Jobs Deamon to manage Tripal Job execution.'),
  22. 'arguments' => array(
  23. 'start' => 'Start the daemon.',
  24. 'status' => 'Display status information about the daemon.',
  25. 'stop' => 'Stop the daemon.',
  26. 'restart' => 'Restart the daemon',
  27. 'show-log' => 'Show the log file.',
  28. ),
  29. 'options' => array(
  30. 'memory_threshold' => 'The maximum memory usage allowed before the daemon should kill itself. Default: 0.85',
  31. 'wait_time' => 'The amount of seconds to wait before checking whether a Tripal Job has been submitted. Default: 60.',
  32. 'file_path' => 'The filepath to store the log and status files to. This should be
  33. either the sites/default/files directory for your Drupal site or the /tmp directory. Default: /tmp.',
  34. 'log_filename' => 'The name of the logfile. Default: tripaljobs_daemon.log',
  35. 'status_filename' => array(
  36. 'description' => 'The name of the file containing a JSON array describing the status of the Daemon. Default: tripaljobs_daemon.status.json',
  37. 'hidden' => TRUE
  38. )
  39. ),
  40. 'examples' => array(
  41. 'drush trpjob-daemon start' => 'Start the daemon.',
  42. //'drush trpjob-daemon start --feedback="100 items"' => 'Log a status message every 100 nodes.',
  43. //'drush trpjob-daemon start --feedback="60 seconds"' => 'Log a status message every 60 seconds.',
  44. //'drush trpjob-daemon start --verbose' => 'Log verbosely.',
  45. ' ' => '',
  46. 'drush trpjob-daemon status' => 'Show the current status of the daemon.',
  47. ' ' => '',
  48. 'drush trpjob-daemon stop' => 'Stop the daemon.',
  49. //'drush trpjob-daemon stop --timeout=10' => 'Allow 10 seconds for processing.',
  50. //'drush trpjob-daemon stop --queue' => 'Queue the node access rebuild daemon to stop.',
  51. ' ' => '',
  52. 'drush trpjob-daemon restart' => 'Restart the daemon.',
  53. //'drush trpjob-daemon restart --timeout=10' => 'Allow 10 seconds for processing.',
  54. //'drush trpjob-daemon restart --queue' => 'Queue the node access rebuild daemon to restart.',
  55. ' ' => '',
  56. 'drush trpjob-daemon show-log' => 'Show the log file, using less.',
  57. //'drush trpjob-daemon show-log --watch' => 'Watch the log file.',
  58. //'drush trpjob-daemon show-log --tail' => 'Show just the tail of the log file, to see recent messages.',
  59. ),
  60. 'aliases' => array('trpjob-daemon'),
  61. );
  62. return $items;
  63. }
  64. /**
  65. * Drush Command for Daemonized management of Tripal Jobs
  66. *
  67. * @param $action
  68. * One of 'start','stop','restart',status','show-log'. Meant to indicate what you want
  69. * the daemon to do.
  70. */
  71. function drush_tripal_daemon_tripal_jobs_daemon($action) {
  72. $details = tripal_daemon_drush_command();
  73. $supported_options = array_keys($details['tripal-jobs-daemon']['options']);
  74. $script_path = drupal_get_path('module','tripal_daemon');
  75. $module_path = DRUPAL_ROOT . '/' . drupal_get_path('module','tripal_daemon');
  76. $output = NULL;
  77. $return_value = NULL;
  78. $options = array();
  79. foreach ($supported_options as $opt) {
  80. $val = drush_get_option($opt);
  81. if ($val) {
  82. $options[] = $opt . '=' . $val;
  83. }
  84. }
  85. $command = "php $script_path/tripal_daemon_script.php $action module_path=$module_path " . implode(" ",$options) . " &";
  86. exec($command); //, $output, $return_value);
  87. /**
  88. drush_print(implode("\n",$output));
  89. switch($return_value) {
  90. case 0:
  91. drush_log("Daemon started successfully.",'ok');
  92. break;
  93. default:
  94. drush_log("Unable to $action the Daemon.",'error');
  95. break;
  96. }
  97. */
  98. }