TripalJobDaemon.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. *
  4. */
  5. class TripalJobDaemon {
  6. // Maximum Memory Threshold
  7. // During Health checks, if the memory usage is over this % usage for the system
  8. // then the child process will kill re-fork and kill itself
  9. protected $memory_threshold = 0.85;
  10. public function get_memory_threshold() { return $this->memory_threshold; }
  11. // How often to check for more Tripal Jobs (in seconds)
  12. // Default is 1 minute (60 seconds)
  13. protected $wait_time = 60;
  14. public function get_wait_time() { return $this->wait_time; }
  15. // The daemon command, such as start, stop, restart
  16. protected $action = '';
  17. public function get_action() { return $this->action; }
  18. // The filepath to store the log and status files to
  19. // This should be either the sites/default/files directory for your Drupal site
  20. // or the /tmp directory and should be set upon creation of the Tripal Daemon
  21. protected $file_path;
  22. // The filename & path of the log file
  23. protected $log_filename;
  24. // The filename & path of the status file
  25. protected $status_filename;
  26. /**
  27. * Creates a new TripalDaemon object
  28. */
  29. public function __construct($args = array()) {
  30. // Set the log/status files
  31. $this->file_path = (isset($args['file_path'])) ? $args['file_path'] : '/tmp';
  32. $this->log_filename = (isset($args['logfile'])) ? $args['logfile'] : 'tripaljobs_daemon.log';
  33. $this->log_filename = $this->file_path . $this->log_filename;
  34. $this->status_filename = (isset($args['status_filename'])) ? $args['status_filename'] : 'tripaljobs_daemon.status.json';
  35. $this->status_filename = $this->file_path . $this->status_filename;
  36. // If the wait time is provided then set it to the provided value
  37. if (isset($args['wait_time'])) {
  38. $this->wait_time = $args['wait_time'];
  39. }
  40. // If the memory threshold is provided then use it instead of our default
  41. if (isset($args['memory_threshold'])) {
  42. $this->memory_threshold = $args['memory_threshold'];
  43. }
  44. }
  45. /**
  46. * Start the Daemon
  47. */
  48. public function start() {
  49. print "Starting the Tripal Daemon...\n";
  50. }
  51. /**
  52. * Stop the Daemon
  53. */
  54. public function stop() {
  55. print "Stopping the Tripal Daemon...\n";
  56. }
  57. /**
  58. * Restart the Daemon
  59. */
  60. public function restart() {
  61. print "Re-Starting the Tripal Daemon...\n";
  62. }
  63. /**
  64. * Show the Status of the Daemon
  65. */
  66. public function status() {
  67. print "Checking the Status of the Tripal Daemon...\n";
  68. }
  69. /**
  70. * Show the Log of the Daemon
  71. */
  72. public function log() {
  73. print "Showing the Tripal Daemon Log...\n";
  74. }
  75. }