tripal_launch_jobs.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @file
  4. * This script will launch any waiting tripal jobs in succession.
  5. *
  6. * This script must be run at the base directory level of the drupal installation
  7. * in order to pick up all necessary dependencies
  8. */
  9. $stdout = fopen('php://stdout', 'w');
  10. // we require one command-line argument
  11. if (sizeof($argv) < 2) {
  12. print_usage($stdout);
  13. exit;
  14. }
  15. $drupal_base_url = parse_url('http://www.example.com');
  16. $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
  17. // $_SERVER['PHP_SELF'] = $drupal_base_url['path'].'/index.php';
  18. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
  19. $_SERVER['REMOTE_ADDR'] = NULL;
  20. $_SERVER['REQUEST_METHOD'] = NULL;
  21. require_once 'includes/bootstrap.inc';
  22. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  23. // check to make sure the username is valid
  24. $username = $argv[1];
  25. $do_parallel = $argv[2];
  26. $max_jobs = (isset($argv[3]) ? $argv[3] : -1; // -1 = don't limit number of consecutive jobs
  27. $results = db_query("SELECT * FROM {users} WHERE name = :name", array(':name' => $username));
  28. $u = $results->fetchObject();
  29. if (!$u) {
  30. fwrite($stdout, "'$username' is not a valid Drupal username. exiting...\n");
  31. exit;
  32. }
  33. global $user;
  34. $user = user_load($u->uid);
  35. fwrite($stdout, date('Y-m-d' H:i:s) . "\n");
  36. fwrite($stdout, "Tripal Job Launcher\n");
  37. fwrite($stdout, "Running as user ' . $username . '\n");
  38. fwrite($stdout, "-------------------\n");
  39. tripal_launch_job($do_parallel, null, $max_jobs);
  40. /**
  41. * Print out the usage instructions if they are not followed correctly
  42. *
  43. * @ingroup tripal_core
  44. */
  45. function print_usage($stdout) {
  46. fwrite($stdout, "Usage:\n");
  47. fwrite($stdout, " php ./sites/all/modules/tripal_core/tripal_launch_jobs <username> \n\n");
  48. fwrite($stdout, " where <username> is a Drupal user name\n\n");
  49. }